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

2

9

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?

Circassian answered 21/2, 2012 at 20:30 Comment(1)
Coming back to this question a year later I can say that I dont use requirejs for production releases anymore. I compile the requirejs modules into 1 file and use almond.js as a lightweight substitute for the amd modules.Circassian
D
4

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...

Duct answered 2/3, 2012 at 13:51 Comment(3)
This sort of answers my question. I'm just wondering if its overload to have 2 resource loaders in 1 page.. should I be combining yepnope with requirejs and just cut out modernizr?Circassian
I think what you meant is cutting out yepnope, keeping Modernizr for the capacity detection and use RequireJS for script loading.Duct
Cont'd....I don't see any problem using both, even performance wise since they are both asynchronous. Nevertheless if you dont't need RequireJS dependency resolution, if I were you I would drop it and keep YepNopeDuct
Q
3

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

Quackenbush answered 24/2, 2012 at 21:27 Comment(3)
Respond.js is a polyfill that Modernizr would use. And I'm thinking that YepNope is included in Modernizr. So, my question is not about a polyfill in particular but is it alright to use modernizr and requirejs together.Circassian
I don't see why not - the worst case scenario is that require.js gets loaded into memory twice.Quackenbush
Cymbals: are you confusing RequireJS with respond.js (module loader/dependency manager vs. media query polyfill)?Recrimination

© 2022 - 2024 — McMap. All rights reserved.