简体   繁体   English

使用外部托管脚本和本地托管脚本之间有速度差异吗?

[英]Is there a speed difference between using externally hosted scripts and locally hosted ones?

I've been using the jQuery library hosted by Google on my site. 我一直在我的网站上使用Google托管的jQuery库。 Will it load quicker if I host it locally? 如果在本地托管,加载速度会更快吗?

Here are a few factors to think about: 以下是一些要考虑的因素:

  1. Cache. 快取。 If you are using the Google hosted jQuery, and another website is using the same version of jQuery hosted with Google, it will be cached locally already. 如果您使用的是Google托管的jQuery,而另一个网站使用的是与Google托管的相同版本的jQuery,则它将已经本地缓存。 Many ISPs will also cache this file for faster delivery to their customers as well. 许多ISP也将缓存此文件,以便更快地将其交付给客户。

  2. Parallel downloading. 并行下载。 Because jQuery will be downloaded from another domain, your maximum connection limit per domain (usually 4 per browser) won't have to queue jQuery. 由于将从其他域下载jQuery,因此每个域的最大连接限制(每个浏览器通常为4个)将不必排队jQuery。

  3. Multiple locations. 多个位置。 Google has servers all over the world, which results in faster downloads for international users. Google在世界各地都有服务器,这可以为国际用户提供更快的下载速度。

Now that said, it is possible that your servers could be lightning fast with multiple locations, and setup for parallel downloading across different subdomains. 如此说来,您的服务器可能会在多个位置快速闪动,并设置为跨不同子域并行下载。 Probably a bigger performance factor is the load priority that will be determined by load order of CSS and Javascript: http://code.google.com/speed/page-speed/docs/rtt.html#PutStylesBeforeScripts 更高的性能因素可能是由CSS和Javascript的加载顺序确定的加载优先级: http : //code.google.com/speed/page-speed/docs/rtt.html#PutStylesBeforeScripts

Hope that helps! 希望有帮助!

Google has a CDN that stretches all over the world. Google拥有遍布全球的CDN。 In addition, most people have probably visited Google or one of its properties at some point before visiting your site-- which means they would already have Google's copy of jQuery cached. 此外,大多数人可能在访问您的网站之前已访问过Google或其属性之一,这意味着他们已经缓存了Google的jQuery副本。

If you're thinking of serving a copy of jQuery off your single server or cluster, Google will certainly beat you (and reduce your bandwidth usage). 如果您打算在单个服务器或群集上提供jQuery副本,那么Google一定会打败您(并减少带宽使用量)。 But if you have a CDN in place from Akamai or similar, you may find it better to serve your own minified copy. 但是,如果您有Akamai或类似机构提供的CDN,则可能会发现最好提供自己的缩小版副本。

Maybe, probably not. 也许吧,也许不是。 Google has a lot of DNS real-estate to minimize long-distance downloads, and there is a chance if you are using a common CDN URL that the user will already have the jquery file cached from visiting another site who used the same external link, and that would eliminate the download completely. Google拥有大量的DNS房地产,可最大程度地减少长距离下载,如果您使用的是通用CDN URL,则有机会通过访问另一个使用相同外部链接的网站来缓存用户的jquery文件,这将完全消除下载。 That's the primary benefit of the CDN. 这是CDN的主要好处。 Google is wicked slower than Akamai though, so if you're looking for sheer speed, Akamai is the way to go. Google的速度比Akamai慢,因此,如果您要寻找绝对的速度,Akamai是您的理想之选。

That being said, the URL you choose will make a difference. 话虽如此,您选择的URL会有所作为。 The major version URL has a short-expires header so it won't stay cached for nearly as long as a minor version URL. 主版本URL具有短过期标头,因此其缓存时间不会与次版本URL差不多。 The minor version URL, though, will drastically reduce the odds that the user visited a site using the same exact minor version. 但是,次要版本网址会大大降低用户使用完全相同的次要版本访问网站的几率。 Your odds are best by using the latest stable minor version CDN URL. 使用最新的稳定次要版本CDN URL,您的赔率最高。

是的,它将快速加载,但是最好与google cdn一起使用,因为它将被google缓存,并且从长远来看会更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM