views:

736

answers:

2

This may be obvious to some, but I've been wondering: why should I depend on Google's server to host jQuery for my site?

Is it only because it loads faster this way?

+52  A: 

This is because:

  1. It increases the parallelism available.
    (Most browsers will only download 3 or 4 files at a time from any given site.)

  2. It increases the chance that there will be a cache-hit.
    (As more sites follow this practice, more users already have the file ready.)

  3. It ensures that the payload will be as small as possible.
    (Google can pre-compress the file in a wide array of formats (like GZIP or DEFLATE). This makes the time-to-download very small, because it is super compressed and it isn't compressed on the fly.)

  4. It reduces the amount of bandwidth used by your server.
    (Google is basically offering free bandwidth.)

  5. It ensures that the user will get a geographically close response.
    (Google has servers all over the world, further decreasing the latency.)

John Gietzen
+1 Excellent answer.
Pekka
I love how you keep coming up with more and more reasons. +1 for that alone.
Matchu
6. Googles servers are probably faster than yours!I'm not sure point 3 is really relevant since anybody can minify just as well as google.+1 for a great answer :)
Paul Creasey
@Paul: Feel free to add that, but generally it is the client connection that is the bottle neck. Thanks!
John Gietzen
I feel like #3 probably has more to do with gzip and the like, since jQuery already gives out a minified version.
Matchu
And another +1 from me, for listing reasons I would not have thought of. Plus I deleted my own sucky answer (which I thought was somewhat acceptable until Mr. I-Know-Why-To-Use-Google-CDN came along :)
karim79
God everyone was attacking me , i just sent my ideas , and was accepted , LOL
farshad Ghazanfari
Joel Potter
@joel-potter : thanks and thats why i deleted my own answer
farshad Ghazanfari
+1 for good reasons
metal-gear-solid
+4  A: 

There are a couple scenarios when you might not want to use jQuery from Google's CDN:

  1. When you are building an intranet application where the webserver is hosted on the same network as the clients. If you use Google's CDN jQuery, you will be making a call to the internet rather than a webserver on the local network. This increases bandwidth for your organization, and is slower.

  2. When you are server pages over SSL that require jQuery. You should server the javascript over SSL as well as your page to avoid security problems and warnings.

Also, Microsoft hosts jQuery on their CDN. That is another choice comparable to using Google's hosted jQuery.

Lance Fisher
Just an FYI that you can use Google's servers to serve up an SSL version of the hosted javascript libraries. https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js works.
Aaron Wagner
Good to know, Aaron. Thanks.
Lance Fisher