我们目前正在从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对这个问题的另一个答案.这是一个很好的把戏

Jquery相关问答推荐

在 Laravel 中使用 jQuery post 按相关值过滤 Select 选项,如何显示从控制器返回的数据?

使用 JQuery 在 span 标签中用逗号分隔页面上的文本

jQuery找到最近的匹配元素

缺少 .map 资源?

动态加载 css 样式表在 IE 上不起作用

Javascript 仅打印 iframe 内容

jQuery:获取所选单选按钮的父 tr

如何在 HTML选项标签上显示工具提示?

在单击事件上判断 Ctrl / Shift / Alt 键

使用 JQuery / JavaScript 调用/单击 mailto 链接

专业的基于 jQuery 的 Combobox 控件?

如何在 jquery 中更新(附加到)href?

如何通过 DOM 容器访问 Highcharts 图表?

自动完成将值而不是标签应用于文本框

如何让 JavaScript/jQuery Intellisense 在 Visual Studio 2008 中工作?

更改 Eclipse 设置以忽略特定文件上的错误

Backbone.js - 事件,知道点击了什么

如何通过jQuery函数仅获取直接子元素

使用javascript将HTML页面中的div下载为pdf

jQuery .val 更改不会更改输入值