飘易博客(作者:Flymorn)
订阅《飘易博客》RSS,第一时间查看最新文章!
飘易首页 | 留言本 | 关于我 | 订阅Feed

Google的jQuery库地址 jquery.min.js在线下载

Author:飘易 Source:飘易
Categories:电脑技术 PostTime:2014-7-19 9:27:10
正 文:
发现google服务器上有很多jquery库:
http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js(54.43kb)
http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js(55.91kb)
http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js(76.76kb)
http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js(83.91kb)
http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js(89.52kb)
http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js(92.62kb)
http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js(91.44kb)

google ajax libraries API 是Google的一个项目(http://code.google.com/apis/ajaxlibs/documentation/index.html#AjaxLibraries)。它提供当前流行的各种Javascript库的快速引用方式。(官方承诺永久可用!)

理论上来说有下面一些优势:
1、采用谷歌的CDN-Content Delivery Network(内容分发网络)加载jquery库。Google离你最近!
2、更好的缓存技术。
  当浏览器检测到同样版本的指向谷歌的链接,它就会知道这是下载同一个文件,不仅是谷歌的服务器会返回一个304(不需要修改文件的指令,即服务器上的文件未改动过)来回复一个重复的请求,而且会命令浏览器的缓存该文件长达一年的时间。
3、减少服务器的请求。
4、它是免费的。

第一种方法:直接饮用js文件
项目中引用Google JQuery库:
<script type=text/javascript src=”http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js”></script>  
<script type=text/javascript> !window.jQuery && document.write('<script src="js/jquery-1.8.3.min.js"><\/script >'); </script>  

注:第二行用来解决最近Google极度不稳定而导致无法正常加载的问题。

有时候并不知道页面是否已经加载了脚本,可以这样:
<script type=text/javascript> !window.jQuery && document.write('<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"><\/script >'); </script>  
<script type=text/javascript> !window.jQuery && document.write('<script type="text/javascript" src="js/jquery-1.8.3.min.js"><\/script >'); </script>  
<script type="text/javascript">  
$(function(){  
    // do somethings here.  
});  
</script>  

第二种,引用api地址
使用google提供的API进行导入
<script src="http://www.google.com/jsapi?key=Goolge"></script>
<script type="text/javascript">
    google.load("jquery","1.3.2",{uncompressed:true});
    google.setOnLoadCallback(initialize);
  function initialize(){
    //函数或方法
  } 
</script>
 
// 测试引用是否成功
$(document).ready(function(e) {
    alert('test!');
});

 
google.load()函数有3个参数,第一个参数为js库的名称,如:"jquery"或 "extjs"等;
第二个参数为该库的版本号,如:"1.3.2";
第三个参数设定是否使用压缩版本的库文件,使用未压缩版本格式: {uncompressed:true} ;
前两个参数必选,第三个参数为可选参数

注:Google Libraries API 还提供了其他主流类库 地址:
http://code.google.com/intl/zh-CN/apis/libraries/devguide.html

来源:
http://blog.csdn.net/xxd851116/article/details/8207581
作者:飘易
来源:飘易
版权所有。转载时必须以链接形式注明作者和原始出处及本声明。
上一篇:没有了
下一篇:通过IP获取用户地理位置省份城市的接口使用
0条评论 “Google的jQuery库地址 jquery.min.js在线下载”
No Comment .
发表评论
名称(*必填)
邮件(选填)
网站(选填)

记住我,下次回复时不用重新输入个人信息
© 2007-2019 飘易博客 Www.Piaoyi.Org 原创文章版权由飘易所有