Latest jQuery version on Google's CDN
I read in the official doc of the Google CDN that this is the src
to jQuery:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
However, it is annoying to have to change my jQuery src
reference at each version update.
I've found that if I set the version to 1
then Google returns the latest version of jQuery.
http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
/*! jQuery v1.8.2 jquery.com | jquery.org/license */
Is this the right thing to do? Is there any official URL to reference the latest version of jQuery hosted on the Google CDN?
UPDATE 7/3/2014: As of now, jquery-latest.js
is no longer being updated. From the jQuery blog:
We know that http://code.jquery.com/jquery-latest.js is abused because of the CDN statistics showing it's the most popular file. That wouldn't be the case if it was only being used by developers to make a local copy.
We have decided to stop updating this file, as well as the minified copy, keeping both files at version 1.11.1 forever.
The Google CDN team has joined us in this effort to prevent inadvertent web breakage and no longer updates the file at http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js. That file will stay locked at version 1.11.1 as well.
The following, now moot, answer is preserved here for historical reasons.
Don't do this. Seriously, don't.
Linking to major versions of jQuery does work, but it's a bad idea -- whole new features get added and deprecated with each decimal update. If you update jQuery automatically without testing your code COMPLETELY , you risk an unexpected surprise if the API for some critical method has changed.
Here's what you should be doing: write your code using the latest version of jQuery. Test it, debug it, publish it when it's ready for production.
Then, when a new version of jQuery rolls out, ask yourself: Do I need this new version in my code? For instance, is there some critical browser compatibility that didn't exist before, or will it speed up my code in most browsers?
If the answer is "no", don't bother updating your code to the latest jQuery version. Doing so might even add NEW errors to your code which didn't exist before. No responsible developer would automatically include new code from another site without testing it thoroughly.
There's simply no good reason to ALWAYS be using the latest version of jQuery. The old versions are still available on the CDNs, and if they work for your purposes, then why bother replacing them?
A secondary, but possibly more important, issue is caching. Many people link to jQuery on a CDN because many other sites do, and your users have a good chance of having that version already cached.
The problem is, caching only works if you provide a full version number. If you provide a partial version number, far-future caching doesn't happen -- because if it did, some users would get different minor versions of jQuery from the same URL. (Say that the link to 1.7 points to 1.7.1 one day and 1.7.2 the next day. How will the browser make sure it's getting the latest version today? Answer: no caching.)
In fact here's a breakdown of several options and their expiration settings...
http://code.jquery.com/jquery-latest.min.js (no cache)
http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js (1 hour)
http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js (1 hour)
http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js (1 year)
So, by linking to jQuery this way, you're actually eliminating one of the major reasons to use a CDN in the first place.
http://code.jquery.com/jquery-latest.min.js may not always give you the version you expect, either. As of this writing, it links to the latest version of jQuery 1.x, even though jQuery 2.x has been released as well. This is because jQuery 1.x is compatible with older browsers including IE 6/7/8, and jQuery 2.x is not. If you want the latest version of jQuery 2.x, then (for now) you need to specify that explicitly.
The two versions have the same API, so there is no perceptual difference for compatible browsers. However, jQuery 1.x is a larger download than 2.x.
如果您希望使用除了Google托管的jQuery库之外的jQuery CDN,则可以考虑使用它并确保使用最新版本的jQuery:
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
I don't know if/where it's published, but you can get the latest release by omitting the minor and build numbers.
Latest 1.8.x:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
Latest 1.x:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
However, do keep in mind that these links have a much shorter cache timeout than with the full version number, so your users may be downloading them more than you'd like. See The crucial .0 in Google CDN references to jQuery 1.x.0 for more information.
链接地址: http://www.djcxy.com/p/91112.html上一篇: 本地存储不起作用