I am using yepnope.js to load javascript files dynamically,and I've noticed that my scripts appear to be loaded twice according to Firebug and Webkit Inspector.
The problem is that in Firebug's Net panel (Firefox 4 latest), their response is a 200
, not a 304
. It seems to be slower than in Chrome.
I have uploaded this video showing the issue. You can see how the files jquery-1.6.1.min.js
and libs.js
are loaded an extra time.
The code I am using to do this is the following, simplified:
Modernizr.load({
load: ['jquery-1.6.1.min.js', 'libs.js'],
complete: function () {
console.log("loaded");
}
});
Modernizr.load()
is yepnope()
.
There's a note about this in their documentation:
From 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.