Skip to content

Instantly share code, notes, and snippets.

@dustintheweb
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save dustintheweb/62f1cc36ef75cb42ac7d to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

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