Using a CDN to serve jQuery
Careful! This post is looking a little old and could be inaccurate in many, many ways
Following the crowd
As a dedicated follower of fashion the next big thing was to start using a CDN (Content Delivery Network) in order to serve jQuery into your website.
It made sense too. As a meaty 70kb file being able to use someone else’s bandwidth is great, but there were other benefits not least the fact users would cache the file possibly making a visit to your website even quicker as jQuery would not need to be re-downloaded.
But for this to be an advantage you have to use a CDN that the majority of other sites are using, for this Google seemed the obvious choice, but what happens if suddenly the file your using disappears?
The answer of course is to have a fallback, self hosted version of jQuery which will be used if your CDN version is no longer available.
$url = "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js";
But it’s Google
Sure it’s Google but it’s both risky and closed minded to assume nothing could ever go wrong with Google. I’m sure no one expects an XSS attack until it’s too late.
For what it a pretty short bit of code you can ensure your website is never affected by a cavalcade of issues that could befall any file you happen to be using on Google’s CDN. I can tell you I’ve had a couple of times where seemingly the CDN doesn’t appear to be loading, they’re short periods, but it has happened.