Download a copy of Modernizr, put it in your plugin’s directory and simply enqueue the script whenever needed. Done.
The problem is that Modernizr may already be loaded by another plugin. You wouldn’t want to load it more than once. How can you find out if Modernizr is already available before enqueueing it yourself? This goes for any other JavaScript library really.
You could check whether a script was loaded by using the wp_script_is()
function. However, that function expects the name of the handle the script was registered by. You can only guess, right? Even if we assume the handle name is simply "modernizr", how do you check for a certain version (like 2.6.1)? Or worse, since custom Modernizr builds are possible, how do you check the features you need are included?
The whole wp_enqueue_script()
setup works fine for libraries that ship with WordPress by default, like jQuery, jQuery UI, Thickbox, etc. Their handle names are documented and you know which version to expect. WordPress doesn’t provide such master files for all JavaScript libraries, of course.
Am I missing something here or is this just the messy situation you somehow have to deal with when developing plugins?