Quick Google CDN jQuery Tip
Here's a quick tip if your using Google's Content Delivery Network (CDN) for serving up jQuery (or other scripts).
So if you want jQuery 1.4.4 you can use a url like this:
Now suppose you just want the latest 1.4.x release, you can use (caution, keep reading):
And if you just want the latest 1.x.x release, you can use this (caution, keep reading):
I would think that using a less specific version number (like 1.4 or just 1) would result in a higher cache hit ratio for your visitors. One drawback to this would be that when a new version comes out your users will start using it without giving you a chance to do any testing.
Update: However if you take a look at the comments, one of my readers points out that there is a big difference in the
Expires http header when using the full version, vs using a version shortcut. Here's what the HTTP headers look like on a request for
Date: Thu, 13 Jan 2011 16:41:02 GMT Expires: Fri, 13 Jan 2012 16:41:02 GMT Cache-Control: public, max-age=31536000
Now here's what they look like when you request just the
Date: Fri, 14 Jan 2011 16:45:21 GMT Expires: Fri, 14 Jan 2011 15:45:21 GMT Cache-Control: public, must-revalidate, proxy-revalidate, max-age=3600
1.4.4 we get a file with an expiration date of next year, and the
Cache-Control with a
max-age of one year.
Now when you look at the request for
1.4 you will notice that the
Expires date is prior to the
Date header, and the
max-age specified in the
Cache-Control header is only one hour.
What are the Pro's and Con's to using Google's CDN to serve up jQuery?
- Google's CDN has a very low latency, it can serve a resource faster than your webserver can.
- There is a good chance that the user may have a cached copy of jQuery from google CDN, so they won't need to download it again.
- Chance are good that the dns lookup for
ajax.googleapis.comis cached by the user as well.
- Because the script is on a separate domain, modern browsers will download the script in parallel with scripts on your domain.
- Google's CDN also works with HTTPS, so you can offload the SSL processing to google's server.
- Additional DNS request may be required, but I'm betting the Pro's make this negligible in most cases.
- May be slower if your site is internal (an intranet for example).
- jQuery UI Sortable Tutorial - January 7, 2010
- GoogleBot Runs AJAX? - December 6, 2006
- 4 Google Tricks - September 21, 2005
- Search Engine Ranking Factors - July 26, 2005
- ColdFusion defaults avoid flawed Random Number Generator
- Apache Security Patches on CentOS / RHEL
- FuseGuard 2.4 Released
- New HackMyCF Features
- Blocking .svn and .git Directories on Apache or IIS
- CFDocs site now Open Source
- Getting Size of Heap and Non Heap Memory in CFML
- Firefox Aurora now Supports Content Security Policy 1.0