javascript - Browserify 和脚本加载优化

标签 javascript jquery browserify

不使用 Browserify 来加载像 jQuery 这样的脚本排除了使用此处概述的 CDN 的潜在好处:

http://encosia.com/3-reasons-why-you-should-let-google-host-jquery-for-you/

"Potentially the greatest benefit of using the Google AJAX Libraries CDN is that your users may not need to download jQuery at all. No matter how well optimized your site is, if you’re hosting jQuery locally then your users must download it at least once. Each of your users probably already has dozens of identical copies of jQuery in their browser’s cache, but those copies of jQuery are ignored when they visit your site. However, when a browser sees references to CDN-hosted copies of jQuery, it understands that all of those references do refer to the exact same file. With all of these CDN references point to exactly the same URLs, the browser can trust that those files truly are identical and won’t waste time re-requesting the file if it’s already cached. Thus, the browser is able to use a single copy that’s cached on-disk, regardless of which site the CDN references appear on."

如果是这样,是否意味着您希望在 <head> 中包含 jQuery并将其排除在 Browserify 包之外?

最佳答案

Doesn't using Browserify to load scripts like jQuery preclude the potentials benefits of using a CDN outlined here:

是的。

would that mean you would want to include jQuery in the <head> and keep it out of your Browserify bundle?

是的,先生,那么您可以使用browserify-shim所以你仍然可以require()浏览器化模块中的 jQuery。

关于javascript - Browserify 和脚本加载优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29613397/

相关文章:

javascript - 数据与 y 轴域不匹配

jquery - 如何在 OnsenUI 框架中对列表进行分页

javascript - 创建一个支持 browserify 和 jQuery &lt;script&gt; 标签加载的包

javascript - 编写通用的 React 输入钩子(Hook)

javascript - 在 javaScript 中给定时间后图像没有改变

javascript - 带有英语和波斯语数字的波斯字符正则表达式

javascript - 递归 require 找不到 Browserify 模块(Babel 后转译)

angularjs - 为什么我不能使用 Angular 和 Browserify 查看源 map ?

javascript - 同时以两种货币显示产品价格?

Javascript 将 [Object object] 输出到文本框(在控制台中工作,而不是在文本框中工作)