Modernizr/Modernizr — Issue #457: How to load jQuery plugins after jQuery fallback is used
Author: Jakobud
Created: 2011-12-20 20:38:40+00:00
State: open

I have the following:

```
Modernizr.load([
{
load: '//ajax.googleapisisoffline.com/ajax/libs/jquery/1.7.1/jquery.min.js',
complete: function()
{
//jQuery fallback
if ( !window.jQuery ) { Modernizr.load('/js/jquery-1.7.1.min.js'); }
}
},
{
load: [
'/js/jquery.simplemodal.1.4.1.min.js',
'/js/jquery.autocomplete.min.js',
'/js/jquery.flexbox.min.js'
],
complete: function()
{
// Do some plugin stuff
}
}]);
```

I'm forcing Modernizr to load the local jQuery here. Then I'm loading up some plugins. Two things happen:

1. After trying to load jQuery from the google CDN (which I'm pretending is offline) the Dev Tools report it as 404. Then there is about a 5-8 second delay where nothing happens. Then all the sudden the jQuery plugins are fetched.
2. The jQuery plugins fail when being loaded because it can't find jQuery (jQuery or $ not defined errors).

Questions:
1. Why is there the 5-8 second lag after the CDN jQuery is not found? Is the response timing out or something?

2. Why can't the scripts find jQuery? It should have been loaded in the fallback, which is easily confirmed by sticking a ```console.log()``` in that fallback block.

3. In Chrome Dev Tools Network Tab, the local ```jquery-1.7.1.min.js``` is not shown as being fetched, but in Firefox Firebug, it does indeed show as being loaded, but the plugins still fail to load.

Is there a more proper way to go about loading jQuery and then plugins? Originally I was just loading jQuery + all plugins async, but realized that if the CDN failed then the plugins would fail also.