使用google.load('jQuery',...)与直接包含托管脚本URL有什么好处? [英] What are advantages of using google.load('jQuery', ...) vs direct inclusion of hosted script URL?

查看:234
本文介绍了使用google.load('jQuery',...)与直接包含托管脚本URL有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google托管一些流行的JavaScript库:
http://code.google.com / apis / ajaxlibs /



根据谷歌:


加载库的最有效方法是使用google.load()...


使用<的优点是什么? / p>

google.load(jquery,1.2.6)



vs。



< script type =text / javascriptsrc =http://ajax.googleapis。 com / ajax / libs / jquery / 1.2.6 / jquery.min.js>< / script>



解决方案

除了Google能够根据请求将多个文件捆绑在一起的好处之外,使用google.load没有任何好处。实际上,如果您知道要使用的所有库(比如jQuery 1.2.6),那么您可能会让用户的浏览器执行一个不需要的HTTP连接。由于使用Google托管的重点是减少带宽消耗和响应时间,因此最好的决定 - 如果您只使用1个库 - 就是直接调用该库。



此外,如果您的网站将使用任何SSL证书,您希望通过Google的HTTPS连接调用脚本来为此做出规划。从http页面调用https脚本没有任何缺点,但从https页面调用http脚本将导致比您想要考虑的更加模糊的调试问题。


Google hosts some popular JavaScript libraries at: http://code.google.com/apis/ajaxlibs/

According to google:

The most powerful way to load the libraries is by using google.load() ...

What are the real advantages of using

google.load("jquery", "1.2.6")

vs.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>

?

解决方案

Aside from the benefit of Google being able to bundle multiple files together on the request, there is no perk to using google.load. In fact, if you know all libraries that you want to use (say just jQuery 1.2.6), you're possibly making the user's browser perform one unneeded HTTP connection. Since the whole point of using Google's hosting is to reduce bandwidth consumption and response time, the best decision - if you're just using 1 library - is to call that library directly.

Also, if your site will be using any SSL certificates, you want to plan for this by calling the script via Google's HTTPS connection. There's no downside to calling a https script from an http page, but calling an http script from an https page will causing more obscure debugging problems than you would want to think about.

这篇关于使用google.load('jQuery',...)与直接包含托管脚本URL有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆