I have a few external js files that I call in my page, at the moment these are called via script tags in the header.

I am tempted to pull these locally and include them in my themes script file to decrease the load time of the page. I know there is an overhead to keeping the scripts up to date but if it decreases the total load time of the page it may be worth it.

Is there a good practice for this? Should I keep them external or is it good to include them in the drupal JS structure?

3 Answers 3


I think it highly depends on what the script is. There are definitely advantages to using third party scripts rather than including them locally. In most cases, I'll try to use the google Library API (http://code.google.com/apis/libraries/) when possible for things like swfobject, webfont loader, and the like. The advantage here is that clients may already have these libraries cached, giving a performance increase over hosting them locally. For situations where there is not a widely used third party host for scripts, I'll usually add them to sites/all/libraries/$library_name and include them locally, so you can take advantage of Drupal's ability to aggregate and minify JS.

  • Agreed on all counts, for stuff like jQuery and popular plugins available on CDNs you might benefit from using the CDN (despite the extra requests) however for most stuff its safe to aggregate & minify and serve it with drupal.js and other scripts as one big heap of js
    – Alex Weber
    Mar 16, 2011 at 17:22
  • 2
    Checkout AdvAgg it can load jQuery from the google cdn. Also has some nice features as well. It's pretty sweet if you ask me ;)
    – mikeytown2
    Mar 17, 2011 at 8:25

The net effect of pulling external scripts locally depends on a lot of factors. Consider for example that:

  • All browsers have limits on the number of resources (Javascript / CSS / Images) they concurrently pull from a given server; increasing the number of resources on a domain can as a consequence increase the total page load;
  • The central distribution points (Google Libraries API, etc.) are geographically distributed and probably more reliable and faster then your own servers;
  • The clients are likely to have the library already in cache if it is distributed from the central distribution point;
  • Drupal 6 is particularly dumb in how it does the aggregation of JS and CSS files, and this can lead in your clients having to download the same library several times if they visit pages on your website that have a different set of Javascript files.

In consequence, I would advise again switching to a local version if you are already using a CDN hosted version.


Look at the emerging module Advanced CSS/JS Aggregation -- it aims to provide the most complete and efficient aggregation system ever.

  • You could probably point out why this is beneficial to the OP.
    – Christian
    May 21, 2015 at 5:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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