Idea
Within #1030822-6: Modernizr 2 custom builder (client-side for admin UI) @lewisnyman suggested that we add each Modernizr test individually into the module, so that you could use a modernizr_add_test() which would be a wrapper for drupal_add_js(), providing feature detection on an inline, page-by-page basis. You would be guaranteed to have the test available when using hook_modernizr_load(), as the module would ensure that all tests print before Modernizr.load() calls.
Given that Modernizr v3 will be entirely modular, this is worth exploring. I think it would be a great 7.x-4.x feature if we were to undertake.
In addition to the current hooks which deal with library integration, this change would allow us to support feature detection within the module itself, closely maintaining parity with the upstream releases.
Benefits
- It would allow modules to efficiently execute tests which are for some reason not included in the current Modernizr build being used on a website. They could be printed inline to save on http requests. We have an issue to detect tests within the current build which would prevent dupe tests: #1569398: "Download Modernizr" link on the settings page should include all tests currently within the JS file.
- It would allow for inclusion of Modernizr tests within Drupal's JS aggregates (in the rare case it is desired).
Drawbacks
None I can think of. It would be optional to use.
Comments
Comment #1
johnalbinHopefully, we'll see some action in this issue now that we've come up with same idea (again!) over in core's queue. #1252178: Add Modernizr to core
I need to clone the Modernizr git repo and do some exploring. When I looked at the master branch last night, I saw https://github.com/Modernizr/Modernizr/tree/master/feature-detects and thought all their detects were already modular. It looks like they still need to move the "core detects" into that directory and out of modernizr.js.
I think we (the Drupal community) need to help out the Modernizr team to get that moving.
Comment #2
ruplJohn, that is a perfect summary of the problem. Here is the Github issue to participate in the effort to move their "core" feature tests out of modernizr.js: https://github.com/Modernizr/Modernizr/issues/486
Comment #3
rupl..and the fix has been committed :)
https://github.com/Modernizr/Modernizr/commit/31147094460fd581d117882d22...
Comment #4
seutje commentedAlex did some great work on turning these into proper modules, and I think we have enough to create a modular builder of our own.
Also, we only have about 2 more weeks to get this ready for Core, but do note that current work on this branch requires Require.js to work properly: https://github.com/Modernizr/Modernizr/tree/3pre
Comment #5
ruplYeah this is definitely not going into the module's 3.0 release, as I'm about to publish that in the next day or two. We can do a 3.5 release or something, but I agree that this is no longer postponed. Thanks for keeping this issue updated, @seutje
Comment #6
ruplJust FYI, this is totally possible today using core API:
Comment #6.0
ruplAdded link to Lewis' original comment.