更好地结合 &缩小 javascript 或使用 Google CDN?
我正在构建一个网站,该网站目前使用多个来源的 javascript:
组 1:Google Maps API v3(由 Google 托管)
第 2 组: jQuery 和 jQuery swfobject(托管在 Google CDN 上)
第 3 组: 几个 jQuery 插件和非 jquery javascript 文件(托管在我的服务器上)
我正在使用 Justin Etheredge 的工具 SquishIt 组合并缩小我的服务器上托管的所有 JavaScript 文件(第 3 组)。
我想知道,如果我将(组 2)中的文件托管在本地,以便它们可以与(组 3)中的所有其他文件合并,并且只需要对组进行一个 HTTP 请求,那么该网站是否会让用户“感觉”更快2& 3. 这意味着我无法获得的好处然而,Google CDN。
有人对此事有什么建议吗?
编辑: 另外,我如何得出这个问题的基于数字的答案?这可能吗?
I am building a site which currently uses javascript from several sources:
Group 1: Google Maps API v3 (hosted by Google)
Group 2: jQuery & swfobject (hosted on Google CDN)
Group 3: Several jQuery plugins and non-jquery javascript files (hosted on my server)
I am using Justin Etheredge's tool SquishIt to combine and minify all the javascript files that are hosted on my server (group 3).
I am wondering if the site would 'feel' faster to users if I were to host the files in (group 2) locally so that they can be combined with all the other files in (group 3) and requiring only one HTTP request for groups 2 & 3. This would mean that I don't get the benefits of the Google CDN however.
Does anyone have any advice on this matter?
EDIT:
Also, how would I come to a numbers based answer to this question? Is that possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为这取决于您的用户在访问使用相同资产的另一个网站时已经缓存了 google cdn 文件的可能性有多大。
我的观点是,最好使用 CDN,因为它被缩小了,而且文件可能根本不需要下载。合并并缩小其他所有内容。
我有兴趣了解那些 google cdn 库文件的全局缓存命中率。
I think it depends on how likely it is that your users already have the google cdn file cached from visiting another site that uses the same asset.
My opinion is that it's better to use CDN since it's minified and somewhat likely the file doesn't need to be downloaded at all. Combine and minify everything else.
I'd be interested to know the global cache hit-miss ratio for those google cdn library files.
使用 CDN 和组合/缩小有不同的目的。如果两者都可以使用的话。
如果你能找到一种方法来使用两者,那就太棒了,
尽管组合 Javascript 文件可能会变成一件更复杂的事情,而不仅仅是缩小它们。
如果需要,您可以使用其他 CDN (Amazon CloudFront)
Using a CDN and combining / minifying serve different purposes. If you can use both.
If you can find a way to use both, its great
Though Combining Javascript files can turn into a more complex affair, than just minifying them.
You can use other CDNs if you want ( Amazon CloudFront )
可能不会有太大区别。
javascript 文件很小并且是静态的,并且将被用户的浏览器缓存。通过使用存储在 Google CDN 中的副本,您的用户甚至不需要在第一次访问您的网站时下载脚本。
不过,通过使用 Google 副本,您也会引入对 Google 的依赖。如果他们的服务器宕机(他们可能不会 - 至少在不久的将来不会),您的网站可能无法正常运行。
Probably won't make much of a difference.
The javascript files are small and static, and will be cached by users' browsers. By using the copy stored in the Google CDN your users might not even have to download the script the first time they visit your site.
By using the Google copy, though, you also introduce a dependency upon Google. If their servers go down (which they probably won't - at least not in the near future), your site might not function correctly.
我正在组合、缩小(使用闭包)并使用(akamai)CDN。但对于 Web 性能最重要的提示是:
异步加载:您可以使用此脚本加载外部js文件
<前><代码>(函数() {
设置超时(函数(){
var sc = document.createElement('script'); sc.type = '文本/javascript'; sc.async = true;
sc.src = 'youfile';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(sc);
},0);
})();
I'm combining, minifying (using closure) and using (akamai) CDN. But the most important tip for web performance are:
async loading: you can use this script to load your externals js files