客户端优化问题

发布于 2024-12-18 08:36:16 字数 234 浏览 0 评论 0原文

考虑以下情况。

  1. 多个 js 文件被压缩/gzip> 并放置在一个文件中,该文件位于 HTML 文档的 head 部分。
  2. 压缩文件(包含少量文件)位于页脚部分(当构建 DOM 时)。

compressed/gzipped javascript 放置在页脚的脚本标记中是否会带来很小的性能提升?

Consider the following casses.

  1. Multiple js files are compressed/gzipped and placed in a one file which is in the head section of the HTML document.
  2. The compressed file(containing few files) is located in the footer section(when the DOM is built).

Is it true that placing compressed/gzipped javascript in script tags at the footer gives small performance boost?

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

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

发布评论

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

评论(3

够运 2024-12-25 08:36:16

是的,将它们向下移动会有帮助。
您也可以执行此操作,也可以从一个脚本调用另一个脚本文件。因此,只需 1 个 HTTP 请求,您就可以并行获取所有 JS 文件。
http://developer.yahoo.com/blogs/ydn/posts/ 2007/07/high_performance_5/

Yes Moving them down will help.
And you can do this as well call another script file from one single script. So With only 1 HTTP request you will fetch all JS files parallely.
http://developer.yahoo.com/blogs/ydn/posts/2007/07/high_performanc_5/

半透明的墙 2024-12-25 08:36:16

密切关注脚本加载器,这是提高性能的另一种方法。指导原则是允许您以非阻塞和有组织的方式加载脚本(包括加载顺序和条件加载),在使用更多 HTTP 请求的同时允许它们并行加载以获得更快的响应。

其中最受欢迎的是 requireJS 但我也更喜欢 head.js 可以对一些 Modernizr 类型的东西执行双重任务。

如果这还不足以让您信服,您仍然可以指定执行顺序(确保满足依赖性)并触发回调。

不过,每种工具都应根据其适用性进行选择。在许多情况下,“移动到页面底部”技术是绝对合适的。您不应该“仅仅因为可以”就使用模块/脚本加载器。

Keep an eye on script-loaders, which are another way of improving performance. The guiding principle is to allow you to load scripts in a non-blocking and organized way (including load order and conditional loading), which while using more HTTP requests allows them to load in parallel for speedier response.

The most popular of these is requireJS but I also rather like head.js which can do double-duty with some Modernizr-type stuff.

If that's not enough to convince you, you can still specify order of execution (ensuring dependencies are met) and fire off callbacks.

Every tool should be chosen for its suitability, though. In many cases, the "move to the bottom of the page" technique is absolutely appropriate. You shouldn't use a module/script loader "just because you can".

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