Typical sample code: yepnope ({test: Modernizr. geolocation, yep: & amp; #39; normal. js & amp; #39;, nope: [& amp; #39; polyfill. js & amp; #39;, & amp; #39; wrapper. js & amp; #39;]}); When Modernizr. geoloca
Typical code example
Yepnope ({
Test: Modernizr. geolocation,
Yep: 'normal. js ',
Nope: ['polyfill. js', 'wrapper. js']
});
When Modernizr. geolocation is true, load the yep item, that is, "normal. js". Otherwise, load the nope item-you can load multiple files at the same time.
What is the difference between yepnope and the existing xxx script loader?
I personally think that the two main points are as follows:
Javascript and css can be processed simultaneously.
All yepnope Parameters
Yepnope ([{
Test:/* boolean (ish)-the expression you want to check for authenticity */,
Yep:/* array (of strings) | this parameter is loaded when string-test is set to true */,
Nope:/* array (of strings) | this attribute is loaded when string-test is set to false */,
Both:/* array (of strings) | string-loaded under any circumstances */,
Load:/* array (of strings) | string-load under any circumstances */,
Callback:/* function (testResult, key) | object {key: fn} execute the corresponding method when a url is loaded successfully */,
Complete:/* the function is loaded and executed */
},...]);
The parameters here can be array or object, which is useful when loading multiple resource files.
Yepnope loads jquery instance www.2cto.com
Yepnope ([{
Load: 'http:/clusters/ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js ',
Complete: function (){
If (! Window. jQuery ){
Yepnope ('local/jquery. min. js ');
}
}
},{
Load: 'jquery. plugin. js ',
Complete: function (){
JQuery (function (){
JQuery ('div '). plugin ();
});
}
}]);
This code asynchronously loads jquery and jquery. plugin. js, and even makes a backup for jquery loading failure.
From touch