1

I've noticed a lot of websites are linking to external scripts located on third party hosts. One very common example is jquery. On serverfault/stackoverflow/superuser jquery is linked to the address at googleapis.com.

What are the benefits of this vs hosting the file on your own site?

Some of the factors can be as follows:

On own host

  • Visitor privacy, not disclosed to third party
  • won't get caught in browser request policies
  • Not dependent on third party uptime

Third party hosting

  • Bandwidth/Traffic
  • Automatic updates

But what are the major reasons for choosing one or the other?

Although I have an opinion of my own my goal with this question is to get an understanding of why other choices are made.

3 Answers 3

3

Speed. We load jQuery, jQuery UI from Google AJAX Libraries API, which increases the chance there's a cached version of those libraries in any visitor's cache. And Google's infrastructure / CDN is better optimized for serving these kinds of static files than our own web server.

Other than that, the bandwidth savings are real - those two libraries are quite heavy together.

Con: I don't trust any other host enough to host a library on their site. For any library not listed on Google, we host it ourself.

1

I think the only real reason is to have always up to date.

I'm against linking libs, scripts, etc because I think my traffic stats are a value to be kept at home.

Moreover it is quite trivial to have the lib hosted and up to date, a cronjob can do the trick easily, efficiently and safely.

0

If you link to a resource to save your bandwidth (or to try improve response times to the user in the case of large common libraries) be aware of two potential major problems:

  1. The external host may go down at some point, due to accident, DoS or planned maintenance. This may cause your site to break so make sure you account for it (if only by giving the user a useful-ish message like "Unable to load JQuery, some features may be broken. Please refresh this page. If the problem persists please report to ..."
  2. When a new version appears it may have some incompatibility with your other code due to a bad assumption (i.e. you have relied on an undocumented or officially undefined behaviour that has changed between versions, or new features bring with them a namespace conflict). This may break your pages until you find and work around the issue.

If you hot-link to a script or anything else of importance to the running of your application make sure that you keep a local copy anyway. That way you can switch to using the local copy as an interim measure if either of the above problems happen and don't get fixed quickly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .