I know what you're all thinking, can't he just use all 3? Yes, I could, but my question is this: do they not cancel each other out?
tl;dr
- Does bundling make RequireJS obsolete?
- Does bundling make CDNs obsolete?
- If I have to make a choice between bundling or RequireJS+CDN, how do I determine which to use? Is it best practice to CDN common files, and bundle uncommon? What about SPA files?
The long version
For example, we bundle files for fewer HTTP requests. Whereas RequireJS is used so that files can be loaded dynamically and asynchronously, as they're needed.
So if we bundle all our JS files into 1, is RequireJS even needed?
Also, we use a CDN so the browser can access a cached version, so if the user visits 5 websites, all of which use a popular jQuery CDN - i.e. http://cdn.com/jquery.min.js - the browser actually needs to make no HTTP requests for this file on the last 4 sites, which is much faster than that file getting bundled. If those sites were to instead each access a unique bundled file from the CDN - specific to their needs - the odds of a cache "hit" become much lower. And, since the odds of a "hit" are lower, the file is less likely to be cached for even the people using that site.
So does it really help for a bundled file to even be on a CDN?