在本地托管 jQuery 的好处与陷阱 [英] Benefits vs. Pitfalls of hosting jQuery locally

查看:12
本文介绍了在本地托管 jQuery 的好处与陷阱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前正在从谷歌 CDN 中提取 jQuery 和 jQueryUI(和 jQueryUI CSS)库.我喜欢这个因为我可以调用 google.load("jquery", "1");
并且将使用最新的 jQuery 1.x.x.

We're currently pulling jQuery and jQueryUI (and jQueryUI CSS) libraries from the google CDN. I like this because I can call google.load("jquery", "1");
and the latest jQuery 1.x.x will be used.

出于安全考虑,现在我要在本地拉取库.

Now I am to pull the libraries locally because of security.

我很高兴将它们拉到本地,但我想知道还有哪些其他好处和需要注意的陷阱?

I'm happy to pull them locally but I'm wondering what are some of the other benefits and pitfalls to watch out for?

推荐答案

将它们放在 CDN 上的主要好处是文件可以与从您自己的网站下载的文件并行下载.这减少了每个页面的延迟.因此,另一方面是在本地托管的一个陷阱 - 延迟增加.主要原因是浏览器可以同时连接到同一个网络域的连接数量受到限制.在 IE6 中,这被默认为 2 个到同一域的并发连接 - 在 IE 的所有打开的窗口之间共享!! 在 IE8+ 中它有所改进,默认为 6,与 FF/Chrome 内联,但仍然,如果你有很多图片并且你没有使用精灵,你会遇到很长的延迟.

The main benefit of having them on a CDN is that the files can be downloaded in parallel to files downloaded from your own website. This reduces latency on every page. So, the flip side of this is a pitfall of hosting locally - increased latency. The main reason for that is that browsers are limited in the number of connections that they can make at the same time to the same web domain. In IE6 this was defaulted to 2 concurrent connections to the same domain - shared between all open windows of IE!! In IE8+ it improved, defaulting to 6, which is inline with FF/Chrome, but still, if you have a lot of images and you are not using sprites, you will experience heavy latency.

使用 CDN,我会始终明确设置库版本,而不是获取最新版本.这降低了新版本破坏代码的风险.jQuery 不太可能,但可能.

Using a CDN, I would always set the library version explicitly rather than getting the latest one. This reduces the risk of new versions breaking your code. Not very likely with jQuery, but possible.

使用 CDN 的另一个主要好处是减少您网站上的流量.如果您按 GB 付费,或者您使用的是资源有限的虚拟服务器,您可能会发现当您将某些内容转移到公共 CDN 时,整体站点性能会提高,托管成本会降低.

The other main benefit of using a CDN is reduced traffic on your site. If you pay per GB or you are on a virtual server with limited resources, you might find that overall site performance increases and hosting costs come down when you farm off some of your content to a public CDN.

请确保您还阅读了@Xaver 对此问题的其他回答.这是一个很好的技巧

Make sure you also read the other answer to this question by @Xaver. This is a very good trick

这篇关于在本地托管 jQuery 的好处与陷阱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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