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

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

问题描述

我们目前正在从谷歌CDN中提取jQuery和jQueryUI(以及jQueryUI CSS)库。我喜欢这个,因为我可以调用 google.load(jquery,1);

将使用最新的jQuery 1.xx 。

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上是文件可以与从您自己的网站下载的文件并行下载。这减少了每页的延迟。因此,另一方面是本地托管的陷阱 - 延迟增加。主要原因是浏览器的连接数量有限,它们可以同时连接到同一个Web域。在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.

确保您还阅读了@revaxarts对此问题的其他答案。这是一个非常好的技巧

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

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

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