Speeding up JS, Playing Well with Others

Another common trick for speeding up JavaScript on a web page is offloading some of it to other sites. Google Analytics and Google Ads are probably the most well-known and ubiquitous. Google also provides the Libraries API, a content distribution network (CDN) for jQuery, Prototype, and other common frameworks, and hosts small projects such as ie7-js. Facebook and Twitter offer their own frameworks for integrating with social media. Then there’s Typekit, which lets you load web fonts from their site, etc.
Since most web browsers limit the number of concurrent requests to any particular host, loading scripts from other sites can get your website to load from your server faster. For some sites, it’s also the best way for them to offer an integration API, with minimal concern for breaking old code (since they control it all).
However, there can be a downside. Loading lots of scripts from other servers makes your website more dependent on those servers, which are outside your control. If any of them are down or inaccessible, it affects the performance and usability of your website as well. I’ve encountered this more often as content offloading has become more common, and its pretty annoying when a page stalls completely for want of some trivial bit of fluff.
What do you think? Does offloading lead to a faster and more usefully integrated web? Or to a house of cards, ready to topple at the first server outage anywhere?


about 1 year ago
Usually you want to optimize and aggregate your Javascript into a limited number of files that are more quickly served and more easily cached, before worrying about connections to a particular host. But once you do start worrying about that, rather than use some third party to host the Javascript bits, why not off load them to a host you control? Just as we’ve done with images and other static assets in moving them off the host(s) which serve dynamic content, one can do that same with Javascript, all within domain(s) controlled by the site owner.
Or am I missing the point, here?
I personally would try hard to avoid making my site’s pages dependent upon fast load of content from other parties. If third party content is optional to getting the page loaded, then it’s not so bad. It’s very frustrating to visit a site and find it not loading, NOT because the owner’s server is not up, but rather because some third-party’s server is not responding. I can’t tell you how many times I’ve had this happen (it should be rare!) and usually I will never visit those sites again.