Is there a link to the "latest" jQuery library on Google APIs?

1,017,127

Solution 1

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

Solution 2

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.

Solution 3

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

Solution 4

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/

Solution 5

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/

Share:
1,017,127
Nick Pierpoint
Author by

Nick Pierpoint

I live in the UK.

Updated on July 08, 2022

Comments

  • Nick Pierpoint
    Nick Pierpoint almost 2 years

    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.)

  • Nick Pierpoint
    Nick Pierpoint over 15 years
    I'd seen that link, which led me to ask about an equivalent one on the "always available" Google link.
  • jcolebrand
    jcolebrand over 13 years
    except that's not really a CDN is it? The question was on the google api (presumed to mean CDN)
  • netvope
    netvope over 13 years
  • Chan Le
    Chan Le almost 13 years
    i wonder why this answer got 22 upvotes while the last one, which contain the same information, got -2 @@
  • Nick Pierpoint
    Nick Pierpoint over 12 years
    @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.
  • ChrisV
    ChrisV about 12 years
    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)
  • Andrew Barber
    Andrew Barber about 12 years
    Welcome to Stack Overflow! Thanks for posting your answer! Please be sure to read the FAQ on Self-Promotion carefully. Also note that it is required that you post a disclaimer every time you link to your own site/product.
  • Joel Purra
    Joel Purra almost 12 years
    It's on a CDN; jQuery CDN (via Media Temple), but the answer may have been true in early 2009.
  • user1087110
    user1087110 almost 12 years
    Check the headers response "Expires". No good caching when loading from Google CDN or jQuery :S
  • Volomike
    Volomike almost 12 years
    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.
  • Scott
    Scott over 11 years
    That works, it is noted already in the accepted answer though.
  • kapa
    kapa over 11 years
    The latest version for the 1.x family, to be correct.
  • hippietrail
    hippietrail over 11 years
    @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 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...
  • Christian
    Christian over 11 years
    Why aren't you using google.com/jsapi directly instead of the http version when you are interested in secure communication?
  • Kai Qing
    Kai Qing over 11 years
    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
  • Amicable
    Amicable over 10 years
    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.
  • thdoan
    thdoan about 10 years
    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.
  • nurettin
    nurettin about 10 years
    I don't get the latest, I get 1.9.1 and latest is 1.10.2
  • Timo
    Timo almost 10 years
    today the link is not working, 502 Bad Gateway. So probably better to use a versioned-link?
  • RhymeGuy
    RhymeGuy almost 10 years
    @Jacob this link is down at the moment..
  • Dave Methvin
    Dave Methvin almost 10 years
    I'm not sure how successful I'll be at dislodging such a popular question, but please see 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.
  • wombling - Chris Paine
    wombling - Chris Paine almost 10 years
    Should be noted that this "latest" link points to 1.11.1 and not the latest version - see blog.jquery.com/2014/07/03/dont-use-jquery-latest-js
  • wombling - Chris Paine
    wombling - Chris Paine almost 10 years
    This is no longer true - see blog.jquery.com/2014/07/03/dont-use-jquery-latest-js and answer by @coliff
  • Martin Seitl
    Martin Seitl over 9 years
    Maybe mention that code.jquery.com does NOT support IPv6. Google and Microsoft do!
  • dre-hh
    dre-hh over 9 years
  • Blazemonger
    Blazemonger almost 9 years
    Also, you're no longer updating that page.
  • dbush
    dbush almost 9 years
    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.
  • Chris
    Chris almost 9 years
    @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?
  • reuns
    reuns over 8 years
    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' ?