gpt4 book ai didi

javascript - 是什么导致我的脚本在使用 Modernizr.load (yepnope.js) 时被请求两次

转载 作者:行者123 更新时间:2023-12-03 12:13:48 25 4
gpt4 key购买 nike

我正在使用 yepnope.js动态加载 javascript 文件,我注意到根据 Firebug 和 Webkit Inspector,我的脚本似乎被加载了两次。

问题是在 Firebug 的网络面板(最新的 Firefox 4)中,他们的响应是 200 ,而不是 304 .它似乎比 Chrome 慢。

我已上传 this video显示问题。您可以查看文件 jquery-1.6.1.min.jslibs.js加载额外的时间。

我用来执行此操作的代码如下,经过简化:

Modernizr.load({
load: ['jquery-1.6.1.min.js', 'libs.js'],
complete: function () {
console.log("loaded");
}
});
Modernizr.load()yepnope() .

最佳答案

在他们的文档中有一个说明:

来自 http://yepnopejs.com/

I'm seeing two requests in my dev tools, why is it loading everything twice?

Depending on your browser and your server this could mean a couple different things. Due to the nature of how yepnope works, there are two requests made for every file. The first request is to load the resource into the cache and the second request is to execute it (but since it's in the cache, it should execute immediately). Seeing two requests is pretty normal as long as the second request is cached. If you notice that the second request isn't cached (and your script load times are doubling), then make sure you are sending the correct cache headers to allow the caching of your scripts. This is vital to yepnope. It will not work without proper caching enabled. We actually test to make sure things aren't loaded twice in our test suite, so if you think we may have a bug in your browser regarding double loading, we encourage you to run the test suite to see if the double loading test passes.

关于javascript - 是什么导致我的脚本在使用 Modernizr.load (yepnope.js) 时被请求两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6400067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com