2

Possible Duplicate:
jQuery Linking vs. Download?

What is the best practice?

  1. Do I include the google api url for jquery or
  2. Do I download the jquery file on my server and use it?

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

Community
  • 1
  • 1
Some Java Guy
  • 4,992
  • 19
  • 71
  • 108

7 Answers7

4

I would prefer to give path of google. for more detailed answer you can go here

  • The google api servers are distributed across the world instead of my single server location: Closer servers usually means faster response times for the visitor.

  • Many people choose to have JQuery hosted on Google, so when a visitor comes to my site they may already have the JQuery script in their local cache. Pre-cached content usually means faster load times for the visitor.

Community
  • 1
  • 1
Adil
  • 146,340
  • 25
  • 209
  • 204
1

Best is to include the google link.

But If for some reason you will develop on a machine without internet access, you should download it on your server.

Klevis Miho
  • 851
  • 8
  • 15
1

If you are working on local then

download a copy and use it.

if on server then

take a cdn link

Reason behind it, it process the page faster.

Jai
  • 74,255
  • 12
  • 74
  • 103
1

Pros of having Google host jQuery for you:

  • Some of your users may already have the script in their caches, as other Web sites may use the same URL to load the same code.
  • Otherwise, Google's server may be geographically closer and therefore latency could be lower.

Cons of having Google host jQuery for you:

  • Connecting to ajax.googleapis.com might require an additional DNS request, increasing load time.
  • For intranet sites, latency will be higher than that of connecting to a server on the same local network.
  • If Google is down (or your site is an intranet site and your Internet connection is down), the script might not load at all.
  • If Google gets hacked, they could deliver malicious JavaScript that impacts your site. Malicious code would have access to anything your users can get to through your site.
  • Google would know your users' IP addresses, which may be a privacy concern.

As for Stack Overflow itself, they do use Google's service despite all the disadvantages.

Community
  • 1
  • 1
PleaseStand
  • 31,641
  • 6
  • 68
  • 95
0

Download jQuery To Your Server. How it Helps:

  1. Can Work Offline.

  2. The Documents Will Load Faster.

Muhammad Talha Akbar
  • 9,952
  • 6
  • 38
  • 62
0

according to him and including me ..:) .. i would go for the 1 option....include the googleapi url...

http://encosia.com/3-reasons-why-you-should-let-google-host-jquery-for-you/

bipen
  • 36,319
  • 9
  • 49
  • 62
0

I think the best practice is to have a fallback in case the CDN is down :

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
// Fallback
<script>!window.jQuery && document.write(unescape('%3Cscript src="js/libs/jquery-1.8.3.js"%3E%3C/script%3E'))</script>

That comes from HTML5 Boilerplate.

wakooka
  • 1,398
  • 10
  • 15