Is there a link to the "latest" jQuery library on Google APIs?
Solution 1
Up until jQuery 1.11.1, you could use the following URLs to get the latest version of jQuery:
- https://code.jquery.com/jquery-latest.min.js - jQuery hosted (minified)
- https://code.jquery.com/jquery-latest.js - jQuery hosted (uncompressed)
- https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js - Google hosted (minified)
- https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js - Google hosted (uncompressed)
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/
Comments
-
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 over 15 yearsI'd seen that link, which led me to ask about an equivalent one on the "always available" Google link.
-
jcolebrand over 13 yearsexcept that's not really a CDN is it? The question was on the google api (presumed to mean CDN)
-
netvope over 13 yearsShorter URL: code.jquery.com/jquery.min.js
-
Chan Le almost 13 yearsi wonder why this answer got 22 upvotes while the last one, which contain the same information, got -2 @@
-
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 about 12 yearsVery 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 about 12 yearsWelcome 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 almost 12 yearsIt's on a CDN; jQuery CDN (via Media Temple), but the answer may have been true in early 2009.
-
user1087110 almost 12 yearsCheck the headers response "Expires". No good caching when loading from Google CDN or jQuery :S
-
Volomike almost 12 yearsI 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 over 11 yearsThat works, it is noted already in the accepted answer though.
-
kapa over 11 yearsThe latest version for the 1.x family, to be correct.
-
hippietrail over 11 years@Jacob: If you use this URL from
https
the result is a site that Chrome will warnThis 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 asworksforme
but I'm sure some people wouldn't be comfortable to use it as it is... -
Christian over 11 yearsWhy aren't you using google.com/jsapi directly instead of the http version when you are interested in secure communication?
-
Kai Qing over 11 yearsAlso 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 over 10 yearsLinking 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 about 10 yearsIf 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 about 10 yearsI don't get the latest, I get 1.9.1 and latest is 1.10.2
-
Timo almost 10 yearstoday the link is not working, 502 Bad Gateway. So probably better to use a versioned-link?
-
RhymeGuy almost 10 years@Jacob this link is down at the moment..
-
Dave Methvin almost 10 yearsI'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 almost 10 yearsShould 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 almost 10 yearsThis is no longer true - see blog.jquery.com/2014/07/03/dont-use-jquery-latest-js and answer by @coliff
-
Martin Seitl over 9 yearsMaybe mention that code.jquery.com does NOT support IPv6. Google and Microsoft do!
-
dre-hh over 9 years
-
Blazemonger almost 9 yearsAlso, you're no longer updating that page.
-
dbush almost 9 yearsWhile 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 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 over 8 yearsare 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' ?