
之前介绍过《当前加载google ajax库的jquery流行版本是1.4.2》和《jquery版本选择与google ajax库加速wordpress效率》。其实Google、Microsoft和Sae都为jQuery,Prototype,MooTools等类库提供CDN服务,无论客户在哪访问网站都是通过CDN访问这些脚本,提高了加载速度,减少了加载延迟并获得更好的缓存。
根据搜索引擎搜索结果来看,利用Google CDN加载jQuery库是最多的,特别是jquery-1.4.2.min.js版本,事实上,大多数网站会缓存jquery,这样从理论上讲,利用Google CDN无疑是最快的。
Google Libraries API
Google: http://code.google.com/apis/ajaxlibs/
但是,理论与实际是有差距的,在国内这个很实际的环境中,Google“被”不稳定,目前尚没办法解决Google CDN库载入“被”缓慢,因此,Google CDN又是“被”最慢的。当然如果你都不介意的话,可以放上一下代码:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script type="text/javascript">window.jQuery || document.write('<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/jquery.min.js">/x3C/script>')</script>
使用上面的代码可以在Google CDN库获取失败时载入本地jQuery库。
Microsoft Ajax Content Delivery Network
Microsoft: http://www.asp.net/ajaxlibrary/cdn.ashx
使用 Microsoft 的 CDN
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.2.min.js"></script><script type="text/javascript">window.jQuery || document.write('<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/jquery.min.js">/x3C/script>')</script>
使用上面的代码可以在Microsoft CDN库获取失败时载入本地jQuery库。
事实上,Microsoft Ajax Content Delivery Network服务器也是在国外的,虽然“被”不能访问的风险较小,但是只要是外国的网络,国内访问的话能快不?
Public Resources on SAE
SAE为新浪为其应用提供的开发者资源,其中就有jQuery库。使用的话非常简单,只要到SAE开发者中心找到合适的地址并替换掉上面代码的CDN地址即可。
<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.4.2/jquery.min.js"></script><script type="text/javascript">window.jQuery || document.write('<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/jquery.min.js">/x3C/script>')</script>
使用上面的代码可以在sae CDN库获取失败时载入本地jQuery库。
总之:建议国内的可以考虑用SAE的开发资源
[anyad]
[url]http://sae.sina.com.cn/?m=devcenter&catId=147[/url]
人吐槽 | 人点赞 |
发表评论