yepnope.js 资源回退不起作用
我直接使用 yepnope 主页上的示例中的代码:
yepnope([{
load: 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js',
complete: function() {
console.log('made it');
if(!window.jQuery) { yepnope('/js/jquery.1.5.2-min.js'); }
}
}]);
今天我一直在没有互联网的情况下工作,我注意到我的本地版本的 jQuery 没有被加载。
由于我没有连接到互联网,我假设在上面的示例中 Google CDN 版本将无法加载,因此将调用 complete
函数来加载我的本地副本。看起来 complete
根本没有被调用,因为我在控制台中没有看到“made it”。
另外,我检查了本地副本的路径是正确的。
I used the code straight from the examples on yepnope's homepage:
yepnope([{
load: 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js',
complete: function() {
console.log('made it');
if(!window.jQuery) { yepnope('/js/jquery.1.5.2-min.js'); }
}
}]);
I've been working without internet today and I noticed that my local version of jQuery is not being loaded.
Since I'm not connected to the internet I would assume in the example above the Google CDN version would fail to load, the complete
function would be called which would load my local copy. It looks like complete
is not being called at all because I am not seeing 'made it' in the console.
Also, I checked and the path to my local copy is correct.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的评论和问题更新进行编辑:
您必须等待它超时。完整的函数不会立即触发。我刚刚下载了 yepnope.js 并运行了他们的 demo/index.html,并在 yepnope 调用下方添加了以下代码,该调用在页面底部加载 jQuery:
显然 jQuery 1.6.2 将不会加载。大约 10-15 秒后,在控制台中,“回调”和“完成”消息都会显示,所以我知道他们将被解雇。
替代方案:
如果您发现您只需要此功能来进行在线/离线开发,您可以尝试 Html5Boilerplate 使用,我已采用:
这是我个人使用的:
EDIT based on your comments and question update:
You have to wait for it to time out. The complete function won't fire immediately. I just downloaded yepnope.js and ran their demo/index.html with the following code added just under their yepnope call that loads jQuery at the bottom of the page:
Obviously jQuery 1.6.2 will not load. About 10-15 seconds later in the console, both the "callback" and "complete" messages show up, so I know they are getting fired.
Alernative:
If you find that you are only needing this functionality for developing online/offline, you might try what Html5Boilerplate uses, which I have adpoted:
Here's what I personally use: