Google 花费了大量的时间来使网络应用变得更快,调用js脚本是我们经常要用到的功能之一,过多的脚本调用经常会使网页变慢。

Google似乎试图来解决这个问题,使大家在使用Javascript框架的时候能够更快速和简单,为此,Google最新提供了一个名为 Ajax Libraries API的东西。

Ajax Libraries API的理念很简单:把Javascript运行在Google的服务器上面, 通过Google快速分发服务器, 当有需要的时候进行Gzip压缩, 更重要的是,使用缓存机制来改善多人同时加载的情况.

使用AJAX Libraries API 有以下优势:

  • 开发者不需要考虑如何设置缓存机制,Google会为你准备好一切
  • 如果另外一个应用程序使用了同一个Javascript框架,那么客户端不再需要重复去获取脚本,因为其已经被缓存在用户的机器里面了。
  • 不需要考虑网络环境和流量限制
AJAX Libraries API 目前支持以下JS框架

Ajax Libraries API调用方式1:

例如:加载Prototype 1.6.0.2

<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js"></script>

Ajax Libraries API调用方式2:

 

 

<script src="http://www.google.com/jsapi"></script> 
<script> 
    
// Load jQuery 
    google.load("jquery""1"); 
    
// on page load complete, fire off a jQuery json-p query 
    
// against Google web search 
    google.setOnLoadCallback(function() { 
        $.getJSON(
"http://ajax.googleapis.com/ajax/services/search/web?q=google&;v=1.0&;callback=?"
    
// on search completion, process the results 
    function (data) { 
        
if (data.responseDate.results && 
            data.responseDate.results.length
>0) { 
            renderResults(data.responseDate.results); 
    } 
    }); 
}); 
</script>

 

相关文章:

  • 2022-01-31
  • 2021-07-27
  • 2021-04-16
  • 2021-10-20
  • 2022-12-23
猜你喜欢
  • 2021-12-20
  • 2021-06-07
  • 2021-10-15
  • 2022-02-02
  • 2021-10-09
  • 2021-08-31
  • 2022-02-07
相关资源
相似解决方案