Skip to content

Instantly share code, notes, and snippets.

@dustintheweb
Last active August 29, 2015 14:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustintheweb/62f1cc36ef75cb42ac7d to your computer and use it in GitHub Desktop.
Save dustintheweb/62f1cc36ef75cb42ac7d to your computer and use it in GitHub Desktop.
Modernizr load CDN script with local fallback
Modernizr.load([{
load: [
'//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'
],
complete: function() {
if (!window.jQuery) {
console.log('## CDN Failed - Loading local version of jQuery.');
Modernizr.load('/js/jquery.min.js');
};
}
}]);
@maxxcrawford
Copy link

The trick is (for other scripts), on the if statement, you have to check for something it loads in.
If it is coded correctly, you can do a similar window.xxxxx check

Example

if (typeof($.fn.owlCarousel) === 'undefined')

This checks to see if it created its global function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment