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.
我们决定停止
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.
由于历史原因,下面这个答案现在还没有定论.
Don't do this. Seriously, don't.
链接到jQuery的主要版本确实有效,但这不是一个好主意——每次十进制更新都会添加和弃用全新的功能.如果您在不测试代码COMPLETELY的情况下自动更新jQuery,那么如果某个关键方法的API发生了更改,您将面临意外的风险.
下面是您应该做的事情:使用最新版本的jQuery编写代码.测试它,调试它,当它准备好投入生产时发布它.
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?
第二个但可能更重要的问题是缓存.许多人在CDN上链接到jQuery,因为许多其他网站都链接到了,而您的用户很有可能已经缓存了该版本.
问题是,caching only works if you provide a full version number.如果您提供了部分版本号,那么future 的缓存就不会发生——因为如果提供了部分版本号,一些用户将从同一个URL获得不同的jQuery次要版本.(假设指向1.7的链接一天指向1.7.1,第二天指向1.7.2.浏览器如何确保今天获得最新版本?回答:无缓存.)
事实上,有here's a breakdown个 Select 权及其到期日
http://code.jquery.com/jquery-latest.min.js(无缓存)
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
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可能也不一定能提供您期望的版本.在 compose 本文时,它链接到jQuery 1.x的最新版本,尽管jQuery 2.x也已经发布.这是因为jQuery 1.x与较旧的浏览器兼容,包括IE6/7/8和jQuery 2.x is not.如果您需要最新版本的jQuery 2.x,那么(目前)您需要显式指定.
这两个版本具有相同的API,因此兼容的浏览器没有感知上的差异.但是,jQuery 1.x的下载量比2.x大.