Performance Tip: When Linking to JavaScript on the Google Ajax Library CDN, Use a Specific Version Number

I’ve seen this a few times over the past few months:


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

What that basically says to Google is “give me the latest 1.* branch version of jQuery and make sure it’s minified.”

Minified is good. Using the Google CDN is good. One thing that’s not so good is the fact that the above file is set with the following headers:


Date: Wed, 23 Jun 2010 18:26:27 GMT
Expires: Thu, 17 Jun 2010 14:26:58 GMT
Age: 2045
Server: GFE/2.0

Notice anything about the expires headers? Yeah, it’s actually set in the past. That’s uncacheable. That makes sense as the purpose of that link is to get the freshest version so you don’t want the browser to hold onto an old version. Thing is, when you’re building a site you want the browser to hold onto a file like that, since it’s the site equivalent of plumbing.

So, instead of using the generic “latest” link format, pin it down to a specific version number


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

Here are those headers:


Content-Type	text/javascript; charset=UTF-8
Last-Modified	Mon, 15 Feb 2010 23:30:12 GMT
Date	Wed, 23 Jun 2010 17:26:41 GMT
Expires	Thu, 23 Jun 2011 17:26:41 GMT

That files expires 1 year from access. That’s what you want.


All of this is ignoring the very real possibility that published code could break as the underlying APIs change. It’s rare over the short term, but if a site live for more than a couple of years the odds are going good something will break because of an update that deprecates or changes some functionality.

This entry was posted in Performance and tagged , , , . Bookmark the permalink.

One Response to "Performance Tip: When Linking to JavaScript on the Google Ajax Library CDN, Use a Specific Version Number"

Leave a reply