jQuery Linking vs. Download?
Asked Answered
G

6

8

Which way is better? To link to the jQuery Pack at http://ajax.googleapis.com. Or to download the appropriate file and link locally? Does it matter? Is there a chance the link may disappear? Or is there a chance the file online will be updated, and it's better to link to it? Curious.

Thanks, Tracy

Goniometer answered 19/1, 2010 at 13:0 Comment(1)
See also "Best way to use Google’s hosted jQuery, but fall back to my hosted library on Google fail" at #1014703Launder
G
7

From the Google Code site:

Google works directly with the key stake holders for each library effort and accepts the latest stable versions as they are released. Once we host a release of a given library, we are committed to hosting that release indefinitely.

One of the main points of Google hosting the jQuery library is so that it is cached in a single place. Consider the following scenario:

  1. User visits site A
  2. Site A has jQuery on the same domain, so the file is downloaded by the browser
  3. User visits site B
  4. Site B has jQuery on the same domain, so the file is downloaded by the browser a second time.

Now if we all fetched jQuery from the Google servers, the scenario goes like this:

  1. User visits site A
  2. Site A loads jQuery from Google, so it's downloaded by the browser
  3. User visits site B
  4. Site B loads jQuery from Google, but the browser already downloaded it and cached it, so fetching the file again is instantaneous.
Gorey answered 19/1, 2010 at 13:9 Comment(1)
That couldn't have been explained any better. Thanks very much, I will definitely go the route of linking directly to the library vs. placing the file on my server. Have a good one! TracyGoniometer
L
7

What if the user comes from a country where Google is banned? Also, some time ago we had to pay for international internet traffic (while regional traffic was "free") in my country an I suspect it may be still the case in some other countries. Users would be upset for having to pay for jQuery. Even minimized. It's safer to keep the files you need on your server.

EDIT: Another reason for not using jQuery from Google servers (if used on your intranet: https://meta.stackexchange.com/questions/10071/employer-blocks-jquery-from-google-doh)

Limestone answered 19/1, 2010 at 13:8 Comment(4)
I guess this is a valid consideration if you target such audiences--I hadn't considered this +1Hunger
But it's not really something to worry about if you don't target such audiences. This is moot if you use a fallback method anyway.Gorey
A fallback method. Please elaborate?? My target audience is definitely local and in the states, but for future reference, is there a way to accommodate both if need be?Goniometer
@Goniometer : see #1014703Limestone
G
7

From the Google Code site:

Google works directly with the key stake holders for each library effort and accepts the latest stable versions as they are released. Once we host a release of a given library, we are committed to hosting that release indefinitely.

One of the main points of Google hosting the jQuery library is so that it is cached in a single place. Consider the following scenario:

  1. User visits site A
  2. Site A has jQuery on the same domain, so the file is downloaded by the browser
  3. User visits site B
  4. Site B has jQuery on the same domain, so the file is downloaded by the browser a second time.

Now if we all fetched jQuery from the Google servers, the scenario goes like this:

  1. User visits site A
  2. Site A loads jQuery from Google, so it's downloaded by the browser
  3. User visits site B
  4. Site B loads jQuery from Google, but the browser already downloaded it and cached it, so fetching the file again is instantaneous.
Gorey answered 19/1, 2010 at 13:9 Comment(1)
That couldn't have been explained any better. Thanks very much, I will definitely go the route of linking directly to the library vs. placing the file on my server. Have a good one! TracyGoniometer
H
1

I think linking to Google's edge cache servers usually makes sense. Google is almost certainly going to have better up time than you and they are likely to be at least as responsive. Plus, there's the advantage that an incoming user has already cached jQuery from them so they don't have to download it at all.

The only situation I can think of where I wouldn't do this would be for a site that was primarily used as in intranet, wherein the local copy would truly be local to most visitors (e.g. on the lan).

Hunger answered 19/1, 2010 at 13:9 Comment(0)
M
0

One important argument for linking to the file on google is that the user might already have the file in his cache, if he's been on another site recently that uses the same url.

Munniks answered 19/1, 2010 at 13:7 Comment(0)
L
0

YOU decide, you control your file or not. One small factor is the bandwidth, but if you have a busy site where that REALLY matters, you will have the bandwidth anyway. What if some small change breaks your site and you have not yet tested with the newer version?

Labrador answered 19/1, 2010 at 13:9 Comment(0)
B
-3

Id reccomend downloading it and storing jquery.js locally on the same server. That way if the linked to file goes down (not that google ever do).

A big argument is that if jquery release an update that removes a function that you need you wont be shafted over and you'll have time to fix it

Bittencourt answered 19/1, 2010 at 13:9 Comment(2)
If you're suggesting that the google links "auto upgrade", that's not true. Google lets you control this behavior by being as precise as desired (e.g. 1.3.x vs. 1.3.1)Hunger
okay, makes sense actually, but surely there is a latest version link?Bittencourt

© 2022 - 2024 — McMap. All rights reserved.