Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use a hosted version of JQuery? Which one?

Tags:

jquery

hosting

Should I use a local copy of jquery, or should I link to a copy provided by Google or Microsoft? I'm primarily concerned about speed. I've heard that just pulling content from other domains can have performance advantages related to how browsers limit connections. In particular, has anyone benchmarked the speed and latency of Google vs. Microsoft vs. local?

Also, do I have to agree to any conditions or licenses to link from a third-party?

like image 849
ataylor Avatar asked May 18 '10 17:05

ataylor


People also ask

What are the advantages of using the hosted jQuery from Google or Microsoft?

One big advantage of using the hosted jQuery from Google or Microsoft: Many users already have downloaded jQuery from Google or Microsoft when visiting another site. As a result, it will be loaded from cache when they visit your site, which leads to faster loading time.

What is the advantage of hosting a jQuery using a CDN?

This is because the jQuery file loads from a CDN and not from the website. In addition, jQuery loads faster when sourced from a CDN that it does when from the website. This is because CDNs will load jQuery files from the closest server to the user.

Should I use Ajax or jQuery?

While JQuery is a library for better client-side web page development, AJAX is a technique of doing XMLHttpRequest to the server from the web page and sending/retrieving data used on a web page. AJAX can change data without reloading the web page. In other words, it implements partial server requests.

Should I use jQuery or JavaScript?

To put things in a nutshell, jQuery is a better option while working with CMS websites like WordPress, Weebly, etc. It makes development easier because of the huge library of plugins it already has. However, even though jQuery is made from Javascript, ignoring vanilla Javascript is not a wise decision.


4 Answers

One advantage would be that a user may already have it cached since another site also linked to a 3rd party.

I've been using google for this and haven't experienced any problems with it so far. You can easily load jQuery using:

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
    google.load("jquery", "1.4");
</script>
like image 128
baloo Avatar answered Oct 20 '22 13:10

baloo


Anytime you use an asset hosted by a third party you increase the number of possible points of failure in your application. You also risk potential bugs resulting from changes made to the asset (say, fixing a bug or updating to a new version) by the hosting party.

Page performance can potentially suffer due to latency differences between your site and the host. Network outages between the client and the host can cause your page to fail, as can internet filtering on the part of their ISP. For instance, using code hosted by Google will cause problems for anyone viewing your site from China.

It's better for security, performance, stability and version integrity to keep all of your assets in one place. Unless you're running a ridiculously high-traffic site, you shouldn't worry about distributing your content.

It's also worth noting that while jQuery isn't exactly a featherweight include, it's not obnoxiously large and, like any JavaScript includes, should be (but is not guaranteed to be) cached by the browser.

like image 34
3Dave Avatar answered Oct 20 '22 14:10

3Dave


Most recommendations I have seen have been to use the hosted version of Google or Microsoft etc.

Dave Ward has a nice article explaining the reasons.

3-reasons-why-you-should-let-google-host-jquery-for-you

  1. Decreased Latency
  2. Increased parallelism
  3. Better caching

See his post for stats.

Dave does point out that you should only do this for Public Facing websites.

like image 31
orandov Avatar answered Oct 20 '22 13:10

orandov


I have been using Google's AJAX library hosting in production for several clients. Works like a charm, and is definitely the best way to go.

http://code.google.com/apis/ajaxlibs/

like image 29
David Souther Avatar answered Oct 20 '22 14:10

David Souther