不使用 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/