views:

46

answers:

4

When using third-party libraries such as jquery, yui-reset, swfobject and so on, do you link to the hosted versions, or download and host your own versions?

Pros and cons either way?

+5  A: 

Hosted versions are apparently the way to go. For three main reasons (edit: I've added a fourth reason, but it's sort of a moot point):

  1. Google/jQuery/etc servers are likely to be faster than your own
  2. A lot of these servers use content distribution so it will be served from a server geographically close to the requester
  3. If every site used the hosted versions, users are more likely to have the files cached in their browsers, so a trip to the server might not even be necessary
  4. They are possibly more reliable than your own server (however if your own server goes down, this point is moot, as you probably won't be able to serve the main page, so there won't be a request to the js file anyway)

Cons would be

  1. You have no control over the uptime/reliability of the servers (though they are more likely more reliable than your own)
  2. Cannot make any custom mods/patches to these files (though most good frameworks allow you to extend them without needing to modify the original code)
  3. If the hosted file does not allow you to specify the version as part of the filename (eg "jquery-1.3.2.js" rather than "jquery.js"), you probably don't want to use the hosted version, as any updates could possibly break your code

I would say the pros generally outweigh the cons.

Graza
+1, These are all the reasons I made my decision on.
Alastair Pitts
Some fine points.
Kyle Sevenoaks
+1  A: 

I always download and host them locally, just because I'm worried about their server downtime, there's no real guarantee that their servers will be up for the rest of time. There is usually a note in the script about who it belongs to anyway.

I guess the only con would be if the person who made the script wouldn't actually want it downloaded.. But I don't see that ever happening.

Plus the requests times are much faster, instead of requesting a script hosted at google, just request it on your own server.

Kyle Sevenoaks
+2  A: 

These are all javascript libraries - You want to put a copy of it on your own server. If you somehow use a different version then you would not have tested against the newer version and it might break your code.

Romain Hippeau
Agreed - most of the time however, hosted versions allow you to be explicit about what version you use (version number is in the file name)
Graza
It is always good to have as much control as possible.
Romain Hippeau
+1  A: 

For production use hosted.

For development use local because if you're offline then your dev site is broke.

zaf