Reputation: 6579
I'm absolute beginner for yepnope and modernizr. I'm trying to test some example. So my question is: when jquery loads from a 3rd party CDN. It's working fine. But when jquery loads from a local, domready function don't work? Why? Am I coding wrong style?
yepnope([{
load: 'http://code.jquery.com/jquery-1.5.9.js'
, callback: function(result, key) {
if(!window.jQuery) {
yepnope('/javascripts/jquery.min.js');
alert("Loaded jQuery from a local!");
} else {
alert("Loaded jQuery from a 3rd party CDN!");
}
}, complete: function() {
$(function(){
alert("DOM ready!");
});
}
}]);
Upvotes: 1
Views: 1461
Reputation: 10451
Your code should work, and is tested in the yepnope test suite.
You may be running into a timeout issue, though. In most browsers, error reporting/handling isn't possible on asynchronous script loading in a consistent or reliable way, so yepnope implements a script timeout in the cases when scripts never call back. So if the version of jQuery you are loading first doesn't exist, it may take 10 seconds (by default, but changeable via yepnope.errorTimeout
) for the callback and complete handler to run. It is an unfortunate downside of trying to load things this way.
Upvotes: 3