我们目前正在从google CDN中提取jQuery和jQueryUI(以及jQueryUI CSS)库.我喜欢这个,因为我可以打google.load("jquery", "1");
现在出于安全考虑,我要把图书馆撤到本地.
I'm happy to pull them locally but I'm wondering what are some of the other benefits and pitfalls to watch out for?
我们目前正在从google CDN中提取jQuery和jQueryUI(以及jQueryUI CSS)库.我喜欢这个,因为我可以打google.load("jquery", "1");
现在出于安全考虑,我要把图书馆撤到本地.
I'm happy to pull them locally but I'm wondering what are some of the other benefits and pitfalls to watch out for?
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.
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.
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对这个问题的另一个答案.这是一个很好的把戏