合并 javascript 文件是否有助于加快 IE8 中的网站速度?

发布于 2024-09-19 22:44:10 字数 214 浏览 7 评论 0原文

PageSpeed和Yslow建议结合javascripts文件来减少HTTPRequest。但这是因为(我认为)ie8之前的浏览器没有超过2个服务器主机连接。

但现在,浏览器有 6 个服务器主机连接,这意味着它可以并行下载 javascript。假设我们有 1MB 的 javascript,我们是否应该将其分成 6 个大小相似的不同文件以获得最大下载速度?请告诉我。

迈克尔·S

PageSpeed and Yslow suggest that to combine javascripts file to reduce HTTPRequest. But this is becuase (I think) pre ie8 browser has no more than 2 serverhost connection.

But nowaday, browser has 6 serverhost connections, which means it has download javascripts in parrallel. So let say we have 1MB of javascript, should we break it down into 6 different files in similar size to obtain max download speed? Please let me know.

Micahel.S

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

白色秋天 2024-09-26 22:44:10

否,因为每个 HTTP 请求都会涉及开销(如果使用管道,则开销会更少)

No, because each HTTP request involves overhead (less if pipelining is used)

萌无敌 2024-09-26 22:44:10

你的问题的答案是否定的。但是,假设您能够在仅使用 IE8 的完全隔离的环境(如公司内部网)中提供内容,那么您的问题的答案就变成:不。

由于您不是为 IE6-7 进行设计,我假设您处于一个孤立的环境中(否则您将做出糟糕的设计决策)。在这种环境下,是的,您可能会发现分解 JavaScript 文件有一些小好处,但我建议不要这样做。

为什么?由于您正在优化速度,我假设您将 JavaScript 放在 HTML 文档中 body 标记的底部,以防止 JS 阻止 DOM 的下载。这是使页面加载速度看起来更快的基本做法。但是,通过将内容放在正文底部,您的问题就变得毫无意义。由于 DOM 不再被脚本标记阻止,因此用户将无法通过使用并行下载获得任何速度优势,因为他们甚至在浏览器请求 JavaScript 文件之前就看到了页面加载。

tl;dr:将JS分成多个文件并行下载并没有实际的速度优势。

The answer to your question is no. However, assuming you are able to serve your content in a completely isolated environment where only IE8 is used (like company intranet), then the answer to your question becomes: no.

Since you aren't designing for IE6-7 I assume you are in an isolated environment (otherwise you are making a poor designing decision). In this environment, yes you might see small benefits from breaking down JavaScript files, but I recommend against it.

Why? Since you are optimizing for speed, I assume you are putting JavaScript at the bottom of the body tag in your HTML document, in order to prevent JS from blocking download of DOM. This is a fundamental practice to make the page appear to be loading faster. However, by placing the content in the bottom of the body, your question becomes moot. Since the DOM is no longer being blocked by the script tags, whatever speed benefits you could achieve by using parallel downloading would be lost on the user because they see the page load before the browser even requests the JavaScript files.

tl;dr: There is no practical speed advantage to break JS into multiple files for parallel downloading.

溺深海 2024-09-26 22:44:10

拆分文件实际上不会产生太大的影响。如果您想在生产环境的下载时间方面看到性能提升,我总是使用 YUI Compressor (http://developer.yahoo.com/yui/compressor/) 使我的 JS 文件大小尽可能小,然后将 js 的 gzip 版本提供给支持它的浏览器。

不过,在开发环境中您不必太担心。只需根据其用途对它们进行逻辑拆分,以便更轻松地处理它们,然后在准备好后将它们全部合并到一个文件中,并对其进行优化以用于生产。

Splitting the files won't make too much of a difference really. If you want to see performance gains in terms of download times for your Production environment what I always do is use YUI Compressor (http://developer.yahoo.com/yui/compressor/) to get my JS file size down as small as possible then serve a gzipped version of the js to browsers that support it.

In a development environment you shouldn't be too worried about it though. Just split them logically based on their purpose so they're easier to work on then bring them all together into one file once you're ready and optimize it for production.

征棹 2024-09-26 22:44:10

无论如何,大多数浏览器都会缓存您的 JavaScript 文件,因此在加载第一个页面后,这并不重要。

但是,您应该以最有利于您开发的方式逻辑地拆分 JavaScript,因为浏览器允许的同时连接数量各不相同。

为了提高速度,您可以混淆代码(通过最小化例程)并以人类没有耐心阅读的方式提供服务。

Most browsers will cache your JavaScript files anyway, so after the first page load, it won't matter.

But, you should split your JavaScript logically and in a way that would most help you in development, since browsers vary in the number of simultaneous connections they allow.

For speed, you can obfuscate your code (via a minimization routine) and serve it in a way no human would have the patience to read.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文