Thursday, April 19, 2012

Why is it not recommended that you bundle require.js with your main.js file

When releasing to production, I concatenate and minify my JavaScript modules (using the AMD pattern) with the require.js optimizer.



The only thing I don't like is the fact that my default, this doesn't include require.js itself ... and so your users still have to make two HTTP calls (one for require, one for your compiled project).



Whilst require.js is small, I don't like making two calls because a) the first call is superfluous and b) it means I have to cache bust require.js as well as my project file (e.g. require.v2.js) note that we don't use querystring cache-busting as this has been shown to operate badly with proxies (i.e. they never cache the resource).






The documentation shows you HOW to bundle require.js into your project, but it also states




It is not recommended that you bundle require.js with your main.js file. Ideally require.js should be the same file contents wherever it is used.




My question is, when they say 'not recommended' - are we talking PURELY architecturally, i.e. can I be sure of having no side-effects?





No comments:

Post a Comment