Reputation: 3284
I'd appreciate your thoughts and advice on the best way to do this. Id like to execute a tiny script — not worth loading — if modernizr test is false. This solution looks a bit clunky.
Modernizr.load({
test: Modernizr.inlinesvg,
yep : 'js/funky-svg-animation.js',
complete : function () {
if (!Modernizr.inlinesvg){
console.log('stuff to do when false');
}
},
});
EDIT: Based on comments, would this be an efficient approach:
if (Modernizr.inlinesvg){
$(body).append('<script src="js/funky-svg-animation.js"><\/script>')
} else {
console.log('stuff to do when false');
}
Or are there problems with this approach?
Upvotes: 1
Views: 656
Reputation: 6075
In Modernizr you have yep
and nope
so if the browser you are testing doesn't support the feature you need, with nope you can do your stuff.
Modernizr.load({
test: Modernizr.inlinesvg,
yep : 'js/funky-svg-animation.js',
nope : 'path/to/your/script.js'
},
});
where path/to/your/script.js is just:
console.log('stuff to do when false');
This is the default behavior of Yenope, that is supposed to load external resources if needed.
Upvotes: 2