How to load js conditional file using modernizr now that yepnope is out of date?

What are some good practices for loading a javascript conditional file using modernizr, now that yepnope and .load are deprecated in the latest version of modernizr.

Used to use the .load function. http://modernizr.com/docs/#load

Modernizr.load({ test: Modernizr.geolocation, yep : 'geo.js', nope: 'geo-polyfill.js' }); 

Now .load is deprecated with yepnope. https://github.com/SlexAxton/yepnope.js/

Link to the answer before yepnope becomes obsolete Loading scripts using Modernizr ... Doesn't work

+7
ruby-on-rails-4 modernizr polyfills yepnope
source share
1 answer

You can use the jQuery getScript method . I think you could also use .fail instead of the else . Spent my morning figuring this out and trying to answer them in order to save people some time!

Something like that?

 if (Modernizr.geolocation) { jQuery.getScript("geo.js") //it worked! do something! .done(function(){ console.log('geo.js loaded'); }); } else { jQuery.getScript("geo-polyfill.js") //it worked! do something! .done(function(){ console.log('geo-polyfill.js loaded'); }); } 
0
source share

All Articles