798

I use the following for a jQuery link in my <script> tags:

http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js

Is there a link to the "latest" version? Something like the following (which doesn't work):

http://ajax.googleapis.com/ajax/libs/jquery/latest/jquery.js

(Obviously not necessarily a great plan to link your code to potentially changing libraries but useful in development.)

John Slegers
  • 45,213
  • 22
  • 199
  • 169
Nick Pierpoint
  • 17,641
  • 9
  • 46
  • 74
  • 7
    Wouldn't that cause a problem with browser caching? The browser wouldn't fetch the newest version because the URL hasn't changed. – JoelFan Nov 20 '11 at 18:16
  • 1
    @JoelFan, not necessarily; it depends on the HTTP headers sent along with the file originally, specifically "Last-Modified" and "Expires". See http://betterexplained.com/articles/how-to-optimize-your-site-with-http-caching/. – Edward D'Souza Dec 07 '11 at 23:04
  • jQuery CDN docs - http://docs.jquery.com/Downloading_jQuery#CDN_Hosted_jQuery – Nick Pierpoint Dec 08 '11 at 10:19
  • 2
    AH! I didn't think about the "potentially changing libraries" part! You are right, for development you want the latest, but if you are giving a site to someone that will most likely not update the scripts, better to leave it at the version that works! – BillyNair May 07 '13 at 00:24
  • 2
    Beware of using jquery-latest.js, its not gonna get updates anymore, See more discussion here http://blog.jquery.com/2014/07/03/dont-use-jquery-latest-js/ – Mukesh Singh Rathaur Sep 03 '14 at 11:26
  • 3
    @NickPierpoint FYI This question is under discussion here: http://meta.stackoverflow.com/q/272570/156755 – Basic Oct 01 '14 at 09:15
  • Linking to the latest version doesn't really make sense, does it? You link to the specific version that you've tested your code and plugins against to keep upgrades from breaking things behind your back. – mu is too short Oct 02 '14 at 19:01
  • 1
    Thanks @Basic - I put a comment on the accepted answer to say that since it was out of date it needed to be updated. If it wasn't updated I would have unaccepted it and either written a consolidated new answer myself or accepted a new one. – Nick Pierpoint Oct 10 '14 at 09:23
  • @BlazeMonger - the duplicate you named was asked 3 years after I asked this question - surely the other question you name is the duplicate. – Nick Pierpoint Feb 17 '15 at 17:02
  • @NickPierpoint The other question has a MUCH better answer, which is probably why this one was closed. – JasonMArcher Feb 17 '15 at 17:49
  • 1
    @JasonMArcher Surely not sensible to close a question as a duplicate that was asked over 6 years ago. Also marked as closed as duplicate by the person who has the accepted answer in the other question. Better to mark the other as duplicate and comment on original question and answers accordingly. – Nick Pierpoint Feb 17 '15 at 22:27
  • @NickPierpoint http://meta.stackexchange.com/questions/147643/should-i-vote-to-close-a-duplicate-question-even-though-its-much-newer-and-ha/147651#147651 – JasonMArcher Feb 18 '15 at 01:21
  • @JasonMArcher I think the community wiki answer I accepted below gives a more succinct a complete answer to the original question while sensibly steering people away from this approach altogether (to reflect the updated question). Perhaps BlazeMonger should instead have updated the accepted answer here if he felt it was incomplete. – Nick Pierpoint Feb 18 '15 at 15:03
  • I don't see this mentioned yet, but you don't seem to be concerned about cross site scripting. Is this a correct assumption? –  Feb 20 '18 at 19:38

12 Answers12

1022

Up until jQuery 1.11.1, you could use the following URLs to get the latest version of jQuery:

For example:

<script src="https://code.jquery.com/jquery-latest.min.js"></script>

However, since jQuery 1.11.1, both jQuery and Google stopped updating these URL's; they will forever be fixed at 1.11.1. There is no supported alternative URL to use. For an explanation of why this is the case, see this blog post; Don't use jquery-latest.js.

Both hosts support https as well as http, so change the protocol as you see fit (or use a protocol relative URI)

See also: https://developers.google.com/speed/libraries/devguide

Archie Butler
  • 455
  • 6
  • 20
Brian Fisher
  • 23,519
  • 15
  • 78
  • 82
  • 3
    Check the headers response "Expires". No good caching when loading from Google CDN or jQuery :S – user1087110 Jun 17 '12 at 17:15
  • 13
    Also FYI using latest WILL destroy your site eventually when the changes begin to cause conflicts. You should target libraries specifically to avoid this unless you are really on top of all your sites – Kai Qing Feb 28 '13 at 23:54
  • 1
    Linking to the google API one is likely to increase your website speed due to the fact that there is a high chance your user already has it cached from another website, and therefore will not need to download it again from you. Hosting it yourself just means the user ends up with multiple copies of jquery in their cache. – Amicable Feb 25 '14 at 11:00
  • If you want to have the latest jQuery library loaded at all times, then load from code.jquery.com because all the other servers are usually a couple versions behind. A small downside is that ajax.googleapis.com usually has less latency than code.jquery.com. – thdoan Mar 19 '14 at 02:20
  • 72
    I'm not sure how successful I'll be at dislodging such a popular question, but please see http://blog.jquery.com/2014/07/03/dont-use-jquery-latest-js/ for why using a direct link to jquery-latest.js is a horrible idea. – Dave Methvin Jul 03 '14 at 17:47
  • 1
    Maybe mention that code.jquery.com does NOT support IPv6. Google and Microsoft do! – Martin Seitl Sep 22 '14 at 16:47
94

DO NOT USE THIS ANSWER. The URL is pointing at jQuery 1.11 (and always will).

Credits to Basic for above snippet

http://code.jquery.com/jquery-latest.min.js is the minified version, always up-to-date.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jacob
  • 1,157
  • 7
  • 2
  • 22
    Shorter URL: http://code.jquery.com/jquery.min.js – netvope Dec 31 '10 at 03:22
  • 4
    i wonder why this answer got 22 upvotes while the last one, which contain the same information, got -2 @@ – Chan Le Aug 10 '11 at 18:40
  • @ChanLe The first time the answer was provided jQuery didn't have a CDN (which was the point of the question). Now that they have one this URL is just as valid as the Google API option. – Nick Pierpoint Dec 08 '11 at 10:11
  • @Jacob: If you use this URL from `https` the result is a site that Chrome will warn `This is probably not the site that you are looking for!` There is a [bug report](http://bugs.jquery.com/ticket/10142) on jQuery's site about this which they've closed as `worksforme` but I'm sure some people wouldn't be comfortable to use it as it is... – hippietrail Nov 18 '12 at 01:25
  • today the link is not working, 502 Bad Gateway. So probably better to use a versioned-link? – Timo Jun 30 '14 at 09:46
  • @Jacob this link is down at the moment.. – RhymeGuy Jun 30 '14 at 13:37
60

Be aware that caching headers are different when you use "direct" vs. "latest" link from google.

When using http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js

Cache-Control: public, max-age=31536000

When using http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js

Cache-Control: public, max-age=3600, must-revalidate, proxy-revalidate
Vilmantas Baranauskas
  • 6,596
  • 3
  • 38
  • 50
  • 7
    Very true - getting a 'latest' version largely loses one of the major benefits of the CDN, that the library will very likely be already cached (either in the user's browser or in some intermediary cache) – ChrisV Apr 24 '12 at 10:42
35

Don’t Use jquery-latest.js

This file is no longer updated (it'll be on v1.11.1 forever). Furthermore it has a very short cache life, (wiping out the benefits of using a CDN) so you'd be better of selecting a version of jQuery instead.

More details on the jQuery blog: http://blog.jquery.com/2014/07/03/dont-use-jquery-latest-js/

coliff
  • 812
  • 8
  • 12
30

Not for nothing, but you shouldn't just automatically use the latest library. If they release the newest library tomorrow and it breaks some of your scripts, you are SOL, but if you use the library you used to develop the scripts, you will ensure they will work.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 4
    There are a couple of times when I really do want the latest, when injecting jQuery into the browser console for instance. – hippietrail Nov 18 '12 at 01:27
18

Use:

<script type="text/javascript" src="//www.google.com/jsapi"></script>
<script type="text/javascript">
//<![CDATA[
    google.load("jquery", "1");
    //google.load("jqueryui", "1");
    //google.load("swfobject", "1");
//]]>
</script>

Note: The above snippet will stick to 1.7.1 or 1.11.1.

My advice for production is to hard code the CDN jQuery version: <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>

You can find the latest Libraries of Google CDN here: https://developers.google.com/speed/libraries/

Or use the jQuery CDN: https://code.jquery.com/

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Plippie
  • 2,836
  • 33
  • 28
7

jQuery also doesn't allow you to call their latest file over SSL, a consideration if you want to use jQuery in a shopping cart etc.

e.g.

<script type="text/javascript" src="https://code.jquery.com/jquery-latest.min.js"></script>

will give you a security error.

Google's API will let you call over SSL:

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
  google.load("jquery", "1.7");
</script>
Matt
  • 74,352
  • 26
  • 153
  • 180
Yarito
  • 161
  • 1
  • 4
  • Why aren't you using https://www.google.com/jsapi directly instead of the http version when you are interested in secure communication? – Christian Jan 14 '13 at 13:56
  • are you suggesting that the best hack of the world would be to inject some code into 'jquery' when websites attempt to get it from 'code.jquery.com/jquery' without 'ssl' ? – reuns Oct 17 '15 at 11:19
6

Yes there is.

http://code.jquery.com/jquery-latest.min.js

Brant Bobby
  • 14,956
  • 14
  • 78
  • 115
Roma
  • 179
  • 1
  • 2
5

No. There isn't..

But, for development there is such a link on the jQuery code site.

nc.
  • 7,179
  • 5
  • 28
  • 38
  • I'd seen that link, which led me to ask about an equivalent one on the "always available" Google link. – Nick Pierpoint Jan 14 '09 at 09:57
  • 2
    It's on a CDN; [jQuery CDN (via Media Temple)](http://docs.jquery.com/Downloading_jQuery#CDN_Hosted_jQuery), but the answer may have been true in early 2009. – Joel Purra Jun 13 '12 at 20:31
  • 1
    Should be noted that this "latest" link points to 1.11.1 and not the latest version - see http://blog.jquery.com/2014/07/03/dont-use-jquery-latest-js/ – wombling - Chris Paine Aug 10 '14 at 16:00
4

What about this one?

http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js

I think this is always the latest version - Correct me, if I'm wrong.

  • That works, it is noted already in the accepted answer though. – Scott Sep 19 '12 at 12:50
  • 1
    The latest version for the 1.x family, to be correct. – kapa Sep 22 '12 at 11:54
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – dbush Jul 24 '15 at 20:30
  • @dbush Seriously? The asker is asking for a link to the latest jQuery and you suggest including the contents of said link (i.e. the jQuery library?) in the answer? Wouldn't that sort of defeat the purpose of having a link that always points to the current version? – Chris Jul 24 '15 at 22:21
1

http://lab.abhinayrathore.com/jquery_cdn/ is a page where you can find links to the latest versions of jQuery, jQuery UI and Themes for Google and Microsoft CDN's.

This page automatically updates with the latest links from the CDN.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Abhinay
  • 35
  • 3
  • 6
    Welcome to Stack Overflow! Thanks for posting your answer! Please be sure to read the [FAQ on Self-Promotion](http://stackoverflow.com/faq#promotion) carefully. Also note that it is *required* that you post a disclaimer every time you link to your own site/product. – Andrew Barber May 14 '12 at 20:59
  • Also, you're no longer updating that page. – Blazemonger Jul 24 '15 at 14:20
-1

You can use the latest version of the jQuery library by any of the following.

  • Google Ajax API CDN (also supports SSL via HTTPS)

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

    /jquery.min.js

  • Microsoft CDN (also aupports SSL via HTTPS)

    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
    

    Ajax CDN Announcement, Microsoft Ajax CDN Documentation

  • jQuery CDN (via Media Temple)

     <script type="text/javascript" src=" http://code.jquery.com/jquery-1.7.2.min.js"></script>
    

    ** Minified version

     <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>
    

    ** Development (Full) version

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
arun
  • 57
  • 1
  • 3
  • 6
    I don't think you understand the OP request. When 1.73 comes out, your code above won't give the OP the latest. The OP is wondering if Google is hosting a CDN of the latest, rather than having to explicitly mention a version. – Volomike Aug 20 '12 at 21:19
  • 1
    http://blog.jquery.com/2014/07/03/dont-use-jquery-latest-js/ – dre-hh Oct 02 '14 at 14:39