我在<script>标记中使用以下jQuery链接:
http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
是否有指向“最新”版本的链接?类似以下内容(不起作用):
http://ajax.googleapis.com/ajax/libs/jquery/latest/jquery.js
(显然,将代码链接到可能变化的库并不一定是一个好计划,但在开发中很有用。)
我在<script>标记中使用以下jQuery链接:
http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
是否有指向“最新”版本的链接?类似以下内容(不起作用):
http://ajax.googleapis.com/ajax/libs/jquery/latest/jquery.js
(显然,将代码链接到可能变化的库并不一定是一个好计划,但在开发中很有用。)
当前回答
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>
注意:上面的代码段将坚持1.7.1或1.11.1。
我的建议是对CDN jQuery版本进行硬编码:<script src=“//ajax.googleapis.com/ajax/libs/jQuery/2.1.4/jQuery.min.js”></script>
您可以在此处找到Google CDN的最新库:https://developers.google.com/speed/libraries/
或者使用jQuery CDN:https://code.jquery.com/
其他回答
请注意,当您使用谷歌的“直接”链接与“最新”链接时,缓存头是不同的。
使用时http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js
Cache-Control: public, max-age=31536000
使用时http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js
Cache-Control: public, max-age=3600, must-revalidate, proxy-revalidate
jQuery也不允许您通过SSL调用他们的最新文件,如果您想在购物车等中使用jQuery,这是一个考虑因素。
e.g.
<script type="text/javascript" src="https://code.jquery.com/jquery-latest.min.js"></script>
会给你一个安全错误。
Google的API将允许您通过SSL调用:
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.7");
</script>
不要使用这个答案。该URL指向jQuery1.11(并且总是如此)。
以上片段的基本学分
http://code.jquery.com/jquery-latest.min.js是缩小的版本,始终是最新的。
您可以通过以下任一方式使用jQuery库的最新版本。
Google Ajax API CDN(也支持通过HTTPS的SSL)<script type=“text/javascript”src=“http://ajax.googleapis.com/ajax/libs/jquery/1.7.2“></script>/jquery.min.jsMicrosoft CDN(也支持通过HTTPS的SSL)<script type=“text/javascript”src=“http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js“></script>Ajax CDN发布、Microsoft Ajax CDN文档jQuery CDN(通过Media Temple)<script type=“text/javascript”src=“http://code.jquery.com/jquery-1.7.2.min.js“></script>**精简版<script type=“text/javascript”src=“http://code.jquery.com/jquery-1.7.2.js“></script>**开发(完整)版本
是的。
http://code.jquery.com/jquery-latest.min.js