In early 2009, I wrote a post on browser caching times for the Google AJAX Libraries API.
The cheat notes are that three different URLs point to the current edition of jQuery and each URL is cached in the browser for a different length of time:
The point of my post was that, when using Google’s AJAX Library to host jQuery, or any of the other libraries, it is best to specify the exact version to receive the full benefit of hosting on the same server as gazillions of other web sites, that being, your visitors don’t need to download the library for every site they visit. I was reminded of this when Dave Ward appeared on episode 32 of the official jQuery podcast.
When jQuery 1.4 was released, the Google URL being publicised by the jQuery team was http://…/jquery/1.4/jquery.min.js – while Google had set it up as http://…/jquery/1.4.0/jquery.min.js. I had two problems with this:
- The publicised URL, coming from the official jQuery team, was only cached for 1 hour;
- Anyone using the publicised URL would automatically be upgraded to jQuery 1.4.1 upon its release, regardless of their expectations.
My request to John Resig and the jQuery team is to avoid confusion by officially numbering the next version as jQuery 1.5.0 and publicising the URL that contains the full version number.
That means that for most people the default version of jQuery they download will be updated least often. It means that the people building the websites have more control over which version of jQuery their end users download and when.
It may seem trivial now but if your visitors leave your site while they’re waiting for jQuery to download, you’ll think it less so.
Update: In the blog post announcing version 1.5, the jQuery team did publicise the 1.5.0 URL on the Google CDN.
I could have used an existing frame work, such as the increasingly popular jQuery; I decided to use my own, which contains only the very basics, rather than have a larger file containing rarely used functions
—source (emphasis added for this post)
Within a couple of months of writing that, I was a convert to jQuery. There was no single reason for my conversion, from memory some of the reasons where:
- the selector engine,
- plugin availability,
- documentation — both official and unofficial tutorials, and,
It’s the last one that probably had the biggest influence, I’m too lazy to reinvent the wheel, and without using a framework that’s what I was going to be doing. Frequently. Examples in blogs I read, weather it be group blogs, such as A List Apart, or one person shows, such as CSS-Tricks were all beginning to use jQuery. If I were to stick to my guns and not use a framework, I’d be doing a lot of rewriting.
As for the functions that are rarely used? It’s really only the Ajax group of functions that I’ve never used, for the simple reason that I don’t like Ajax. In many of the situations it’s used, it is often fanciness without necessary function. Then again, ask me about Ajax in a couple of months’ time.
Using the Google AJAX Libraries API, there are several options for specifying the version numbers of the library you wish to use, for example the following URLs all point to the latest version – at the time of writing – of jQuery.
- http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js, and,
The first uses the latest release in the version 1 tree, the second the latest in the version 1.3 tree, and the third the release 1.3.0 exactly. What I found interesting – and discovered accidently – is the browser caching times for each of these urls; the first two are cached for an hour, the third for twelve months.
The vastly different caching times make perfect sense, in the first two cases, the developer is expecting an upgrade to the latest version, and doesn’t want to wait up to twelve months for it; in the third case the developer doesn’t expect an upgrade so an extended caching period has no effect.
To take full advantage of the Google servers, as described in a recent article by Dave Ward, the caching times suggest it’s best to specify the full version of the library you wish to use.
google.load Method – Update Jan 24, 2009