Bundling .js files vs CDN Bundling .js files vs CDN asp.net asp.net

Bundling .js files vs CDN


Why can't you bundle them and place them are the CDN? It should hardly be a decision of one or the other?

If you have to choose one or the other, it depends on how many .js files you are including. For a small number of files, I'd suggest that a CDN would be quicker, where-as for a greater number of files, a bundle of .js files would definitely be quicker. Where the switch-over would be, is something for you to experiment with.


My answer: both. Bundle them and place them on a CDN.

The downside of doing this? Depends. What does you build process look like? Can you easily automate the bundling and minification? Are you using Yahoo YUI or Google Closure or something else?

Also, if there is a lot of GUI dependent jQuery there might be some time consuming friction due to constantly changing elements/effects/css.

Testing is important too because due to possible minification quirks.

Bottom line: 5 javascript files safely bundled into 1 file === 4 fewer requests.

A page with just plain old Html and one external javascript reference === 2 requests to your server. However, a page with just plain old Html and one external javascript reference on a CDN === 1 request to your server.

Currently we are using the Google Closure tools. The Google Closure Inspector helps with the following:

Closure Compiler modifies your original JavaScript code and produces code that's smaller and more efficient than the original, but harder to read and debug. Closure Inspector helps by providing a source mapping feature, which identifies the line of original source code that corresponds to the compiled code.


As others have already stated, the answer is both if possible. Bundled (and minifying) gives a benefit to your users because it decreases the page weight. The CDN benefits your servers because you are offloading work. Generally speaking, you need not optimize either unless you have observed performance issues or you just have nothing better to do.