ajaxapi,Ajax Libraries API调用JavaScript...

留个备份
在还不知道Google’s Ajax Libraries之前,我想大多数jquery新手在使用jquery的时候都是直接将jquery下载下来,然后通过在JavaScript脚本中使用src链接jquery库。我不得不承认jquery1.4的版本中,许多方法都得到了性能上的改进,无论是从方法的扩展性,还是加载速度上面都比之前的jquery版本提升了一个级别。不过在我了解Google’s Ajax libraries API之后,发现它在加载这些JavaScript库,包括jquery,jquery ui,yui等流行框架,有着优越的性能。google官方网站上对google ajax libraries API的解释是:
The AJAX Libraries API is a content distribution network and loading architecture for the most popular, open source JavaScript libraries. By using the Google AJAX API Loader’s google.load() method, your application has high speed, globaly available access to a growing list of the most popular, open source JavaScript libraries including:
01.jQuery02.jQuery UI03.Prototype04.script.aculo.us05.MooTools06.Dojo07.SWFObject08.Yahoo! User Interface Library (YUI)09.Ext Core10.Chrome Frame11.WebFont Loader
总而言之,通过使用Google’s Ajax Libraries API 访问JavaScript开源库大大降低你的服务器带宽,让web应用程序加载速度更快。下面一jquery为例具体来介绍一下Google’s Ajax Libraries API的使用方法:
01.在JavaScript中指定src属性你可以通过在引用JavaScript脚本时指定加载jquery的具体路径,目前最新的jquery版本是1.4.2,像这样:
<script type='text/javascript'src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js?ver=1.4.2'></script>
02.使用load方法你还可以通过使用api中的load方法将加载jquery的请求加载到web应用程序。
<script type="text/javascript">google.load("jquery", "1.4.2");</script>
下面是一份调用其他最新JavaScript框架的清单:
google.load("jquery", "1.4.2"); google.load("jqueryui", "1.8.2"); google.load("prototype", "1.6.1.0"); google.load("scriptaculous", "1.8.3"); google.load("mootools", "1.2.4"); google.load("dojo", "1.4.3"); google.load("swfobject", "2.2"); google.load("yui", "2.8.1"); google.load("ext-core", "3.1.0");
调用是不是很简单呢?从上面可以总结出load方法的参数含义。load(parameter1,parameter2);第一个参数指定所调用的JavaScript库的名字,第二个参数指定加载JavaScript库的版本号。
下面将目前可以得到的JavaScript库的所有清单举例如下,在清单中你可以很清楚地了解各个优秀的JavaScript开源库的版本情况,加载方法等信息,我也会在这些开源库更新版本的同时更新我的这份清单:
jQuery
name: jquery
versions: 1.2.3, 1.2.6, 1.3.0, 1.3.1, 1.3.2, 1.4.0, 1.4.1, 1.4.2
load request: google.load("jquery", "1.4.2");
extras: uncompressed:true, e.g., google.load("jquery", "1.4.2", {uncompressed:true});
path: http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
path(u): http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js
site: http://jquery.com/
note: 1.2.5 and 1.2.4 are not hosted due to their short and unstable lives in the wild…
jQuery UI
name: jqueryui
versions: 1.5.2, 1.5.3, 1.6, 1.7.0, 1.7.1, 1.7.2, 1.7.3, 1.8.0, 1.8.1, 1.8.2
load request: google.load("jqueryui", "1.8.2");
extras: uncompressed:true, e.g., google.load("jqueryui", "1.8.2", {uncompressed:true});
path: http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js
path(u): http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.js site: http://jqueryui.com/&#65533;
note: This library depends on jquery. Before loading this module, you must load jquery. e.g.:
google.load("jquery", "1.4.2"); google.load("jqueryui", "1.8.2");
Prototype
name: prototype
versions: 1.6.0.2, 1.6.0.3, 1.6.1.0
load request: google.load("prototype", "1.6.1.0");
path: http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js
site: http://www.prototypejs.org/
script.aculo.us
name: scriptaculous
versions: 1.8.1, 1.8.2, 1.8.3
load request: google.load("scriptaculous", "1.8.3");
path: http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.3/scriptaculous.js
site: http://script.aculo.us/
note: This library depends on Prototype. Before loading this module, you must load Prototype. e.g.:
google.load("prototype", "1.6"); google.load("scriptaculous", "1.8.3");
MooTools
name: mootools
versions: 1.1.1, 1.1.2, 1.2.1, 1.2.2, 1.2.3, 1.2.4
load request: google.load("mootools", "1.2.4");
extras: uncompressed:true, e.g., google.load("mootools", "1.2.4", {uncompressed:true});
path: http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js
path(u): http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools.js site: http://mootools.net/
note: Since 1.1 versions are not compatible with 1.2 versions, specifying version “1″ will map to the latest 1.1 version (currently 1.1.2).
Dojo
name: dojo
versions: 1.1.1, 1.2.0, 1.2.3, 1.3.0, 1.3.1, 1.3.2, 1.4.0, 1.4.1, 1.4.3
load request: google.load("dojo", "1.4.3");
extras: uncompressed:true, e.g., google.load("dojo", "1.4.3", {uncompressed:true});
path: http://ajax.googleapis.com/ajax/libs/dojo/1.4.3/dojo/dojo.xd.js
path(u): http://ajax.googleapis.com/ajax/libs/dojo/1.4.3/dojo/dojo.xd.js.uncompressed.js
site: http://dojotoolkit.org/
SWFObject
name: swfobject
versions: 2.1, 2.2
load request: google.load("swfobject", "2.2");
extras: uncompressed:true, e.g., google.load("swfobject", "2.2", {uncompressed:true});
path: http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js
path(u): http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject_src.js
site: http://code.google.com/p/swfobject/
Yahoo! User Interface Library (YUI)
name: yui
versions: 2.6.0, 2.7.0, 2.8.0r4, 2.8.1
load request: google.load("yui", "2.8.1");
extras: uncompressed:true, e.g., google.load("yui", "2.8.1", {uncompressed:true});
path: http://ajax.googleapis.com/ajax/libs/yui/2.8.1/build/yuiloader/yuiloader-min.js
path(u): http://ajax.googleapis.com/ajax/libs/yui/2.8.1/build/yuiloader/yuiloader.js
site: http://developer.yahoo.com/yui/
Ext Core
name: ext-core
versions: 3.0.0, 3.1.0
load request: google.load("ext-core", "3.1.0");
extras: uncompressed:true, e.g., google.load("ext-core", "3.1.0", {uncompressed:true});
path: http://ajax.googleapis.com/ajax/libs/ext-core/3.1.0/ext-core.js
path(u): http://ajax.googleapis.com/ajax/libs/ext-core/3.1.0/ext-core-debug.js
site: http://extjs.com/products/extcore/
Chrome FrameNew!
name: chrome-frame
versions: 1.0.0, 1.0.1, 1.0.2
load request: google.load("chrome-frame", "1.0.2");
extras: uncompreassed:true, e.g., google.load("chrome-frame", "1.0.2", {uncompressed:true});
path: http://ajax.googleapis.com/ajax/libs/chrome-frame/1.0.2/CFInstall.min.js
path(u): http://ajax.googleapis.com/ajax/libs/chrome-frame/1.0.2/CFInstall.js
site: http://code.google.com/chrome/chromeframe/
WebFont LoaderNew!
name: webfont
versions: 1
load request: google.load("webfont", "1");
extras: uncompressed:true, e.g., google.load("webfont", "1", {uncompressed:true});
path: http://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js
path(u): http://ajax.googleapis.com/ajax/libs/webfont/1/webfont_debug.js
site: http://code.google.com/apis/webfonts/docs/webfont_loader.html
越来越多的优秀的JavaScript框架正在加入现代web应用程序中,chrome frame和webfont就是比较新的两款JavaScript框架。你也可以通过Google’s Ajax Libraries API加载,使用API无疑在提高你的服务器性能、降低你的网络带宽上带来一定的功效。
Tags:  ajaxapi

延伸阅读

最新评论

发表评论