I notice this is the case mainly for rather sophisticated pages. However, why don't developers simply combine the JS files and condense it all together? Is it not a more efficient method, in terms of requests? I am not sure if it is but it would seem that way.


When talking about efficiency, as has been noted already, you've really got two issues.

  • Efficiency in the development process
  • Efficiency in delivering the site to the end user

It may perhaps be argued, but I think it fairly obvious that delivery is a higher priority. However when it comes to including scripts and dealing with changes in the site, having one massive 'god script' is a giant pain. Modularity is king of maintainability imho.

One solution, like that mentioned by Ewan about Drupal, is to use your server-side language to dynamically 'compile' a JS file or two putting the whole mess together any time the code changes. Depending on how you achieve this it is possible to go ahead and use many sources during development and only one or a small number of them in production.

There are also a few other practical matters to consider:

  • You can offload some of your bandwidth for scripts that are hosted by services such as Google Libraries API or Yahoo's YUI. Increasingly, users have these files already onhand from other sites and, if nothing else, loading your site from more connections will speed up delivery.
  • There are cases where you don't need the same functionality on every page and want to easily leave out some scripts while keeping the ones relevant to the current page.
  • Every now and then you may actually want to load individual scripts after load-time using AJAX and whatnot based on the user's browsing context.
  • 1
    And you can use something like Ant to compress and minify all the scripts into one. Html5Boilerplate handles this for you.
    – Dan Blows
    May 6 '11 at 15:50

It's easier to develop a site if the scripts are separate but usually better to combine them for delivery as long as they aren't going to interact with each other.

The reduction of requests will usually make the page load faster. Also, a combined script can usually be compressed to a smaller size than each individual file.

The main reason files aren't combined is probably laziness but it's not actually too difficult to write a script to do it automatically. Some CMS systems, such as Drupal, have an option to send all the JavaScirpt in a single file.


It's easier not to. You take a bit of jQuery here and another useful script from there and just include both, and so it goes on. If you don't combine them it also makes upgrading one particular bit, like your jQuery library, easier.

Also, if you're using some sort of CMS which uses lots of scripts then unless you want to modify the CMS and possibly break it, you put it up with so many scripts.

Talking of jQuery, it's a good idea to use Google's content delivery network http://code.google.com/apis/libraries/devguide.html#jquery . However that means that if you have another script you're using multiple scripts again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.