Skip to Main Content

If you’re a developer, you’ll often see websites hosting their own copy of jQuery, a JavaScript library.  They don’t have to.  Instead, we urge you to use Google’s  content delivery network (or CDN) to serve jQuery (and other JavaScript libraries) to your users.   Why?  Doing so has some real advantages.  Let’s look at just the top 3.

If all you want is the link, here it is, or check the Developer library for all of them:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

NOTE: This post is only about WHY you should be using Google’s jQuery CDN.  This post was inspired by Dave Ward’s article, “3 Reasons why you should let Google host jQuery for you,” which deep-dives into various implementations too complex to be covered here.

01. Decreased Latency

A CDN distributes your static content across servers in various, diverse physical locations. When a user’s browser resolves the URL for these files, their download will automatically target the closest available server from that diverse network.  Here’s how a CDN works.

In the case of Google’s CDN, what this means is any users not physically near your server will download jQuery faster than if you force them to download it from your server which could be located anywhere.

There are a handful of CDN services from hosting providers comparable to Google’s, but it’s hard to beat the price of free and the speed of Google!

02. Increased parallelism

To avoid needlessly overloading servers, browsers limit the number of simultaneous connections. Depending on the browser, this limit may be as few as 2 connections per hostname.

Using Google’s jQuery CDN eliminates at least one request to your site, allowing more of your local content to be downloaded in parallel.  That means a faster website and faster is always better in digital.

03.  Better caching

Last, but certainly not least, is if your users have already cached jQuery from Google’s CDN, they don’t have to load it at all!

If you’re hosting jQuery locally then your visitors must download it at least once. Each of your visitors has probably already viewed sites using identical copies of jQuery, but those copies of jQuery are ignored when they visit your site (different hostnames).

However, when a browser sees references to CDN-hosted copies of jQuery (same hostname), it understands all of those references refer to the exact same file. Thus, it skips re-downloading it entirely.

CDNs, such as Google’s, create a potent “cross-site caching” effect which all sites using the CDN benefit from.  Since Google’s hosted version of jQuery serves the file with headers that attempt to cache the file for up to one year, this effect truly has amazing potential.

The Proof is in the Pudding

According to a recent study, Google will consume 16.5% of all consumer Internet capacity in the United States during 2008.   I think it’s fair to say they know how to efficiently serve up some content.

So, why aren’t you using Google’s CDN?

Share the love:

Discussion

Comments are now closed.

Get the Email

Join 1000+ other subscribers. Only 1 digest email per month. We'll never share your address. Unsubscribe anytime. It won't hurt our feelings (much).

Preview Email