Skip to content

Which Google jQuery hosted link to use?

July 21, 2010

As you probably know, the best way to load jQuery on an internet website is to get it from Google’s CDN. There are three main reasons for this:

  1. Parallelism – Browsers limit the number of simultaneous connections to a single server to avoid overload. Any resource that you fetch from a different server than your own will starting loading immediately, rather than being queued up alongside the images, scripts, CSS etc coming from your main server.
  2. Speed – Google’s CDN has many servers in different physical locations, and your user will be automatically directed to the server that will serve their request most quickly.
  3. Caching – Most importantly, if the user has already been to a site that uses the same version of hosted jQuery, their browser will already have a local copy and won’t need to download it at all.

However, it’s important to make sure that you use the right URL to load jQuery. Let’s suppose my site works with jQuery 1.4.2 (the latest version at the time of writing). I can actually use three different URLs to get it:

  • – This is version 1.4.2, as you would expect. If you’ve tested against 1.4.2 and don’t want any surprises, this is the one for you.
  • – This is the latest revision of version 1.4, so while it loads 1.4.2 at the moment, your site will be automatically upgraded to 1.4.3 when it’s released. However, if and when 1.5 is released you won’t get it, which protects you from any breaking changes that might be introduced.
  • – This is the latest revision of version 1. You’ll always get the latest and greatest jQuery (until they release version 2), but you do need to keep an eye out for breaking changes. This is the default setting in DotNetNuke when you enable hosted jQuery, so if you’re using this setting then you may want to give your site a quick test when a new version of jQuery is released to the Google CDN (subscribe to Google AJAX API Alerts to know when this happens).

Also worth noting if you’re fine tuning for performance is that if you specify the exact version number then jQuery will be cached in the browser for up to a year, giving the best possible performance. If you only specify a partial version then the browser will still check the Google server every hour to see if there’s a new version available, even though it won’t actually download it if nothing’s changed.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: