Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use Modernizrjs + YepNopejs + Requirejs in the same page?

I'm using RequireJs for structuring my JavaScript code. Also, I'm using a lot of CSS3 and I use "Modernizr w/ YepNope" + x number of css3 polyfills.

I understand "Modernizr w/ YepNope" and RequireJs are both Resource Loaders. Since they are both resource loaders is it a bad idea to use both of them in the same project?

So, basically I'm asking, is it a bad idea to use:

  • Require.js
  • Modernizr.js w/ YepNope.js

In the same page?

like image 859
Evan Larsen Avatar asked Feb 21 '12 20:02

Evan Larsen


2 Answers

As long as you don't load RequireJS modules via YepNope it is ok to use both. Otherwise you could encounter this issue according to the RequireJS doc : http://requirejs.org/docs/errors.html#mismatch

And since you load stuff outside RequireJS, i.e. an API polyfill, the only way your modules could use those polyfills would be to make the initial require() call within the complete() callback of YepNope. But IMHO it gets a bit clunky...

like image 97
sylvain Avatar answered Sep 24 '22 13:09

sylvain


Summary: Respond.js, (which is great with jQuery Mobile), is based on css3 media queries, so if polyfills is all you need, you probably do not 'need' resource loaders.

I cannot speak for YepNopejs, but since respond.js is listed in Modernizer, it seems redundant.

Modernizer, if used, should determine whether or not respond.js is loaded.

Modernizer will conditionally load the scripts, including respond.js, client-side based on feature detects. Supported scripts (which do not currently include YepNope) at

https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills

like image 32
Cymbals Avatar answered Sep 25 '22 13:09

Cymbals