yepnope.js 异步加载资源文件

yepnope.js 异步加载资源文件Yepnope.js是一个js脚本,可以根据输入条件有选择地异步加载资源文件,在页面上只能加载用户需要的js/css。一个典型的代码示例如下复制代码:YEP NOPE({ test:modernizr . geolocation,YEP: normal.js ,NOPE: [polyfill.js , wrapper . js ]});当Modernizr.geolocation为真时,加载yep项,即“normal . js”;否则,加载nope项3354会同时加载多个文件。yepnope和现有的xxx脚本加载器有什么区别?我个人认为主要是这两点:可以同时处理javascript和css。yepnope的所有参数都可以有条件地加载。按如下方式复制代码:Yep nope([{ test:/* boolean(ish)-要检查真实性的表达式*/,Yep:/* array(of strings)| load this item When string-test为true */,nope:/* array(of strings)| load this item When string-test为false */,Both:/* array(of strings)| string:/* array(of strings)| string-load */,callback:/* function (test result,Key) | object {key: fn}执行此方法*/},]);这里的参数可以是数组或对象,这在加载多个资源文件时很有用。yepnope加载jquery的示例复制代码代码如下:Yep nope([{ load: http:/shy;/Ajax . Google APIs . com/Ajax/libs/jquery/1 . 5 . 1/jquery . min . js ,complete: function () { if(!window . jquery){ Yep nope( local/jquery . min . js );} } },{ load: jquery.plugin.js ,complete:function(){ jQuery(function(){ jQuery( div )。插件();});} }]);这段代码异步加载jquery和jquery.plugin.js,甚至为jquery失败的情况做了备份。

yepnope.js 异步加载资源文件