<bdo id='kOn3J'></bdo><ul id='kOn3J'></ul>
      1. <small id='kOn3J'></small><noframes id='kOn3J'>

        <tfoot id='kOn3J'></tfoot><legend id='kOn3J'><style id='kOn3J'><dir id='kOn3J'><q id='kOn3J'></q></dir></style></legend>
        <i id='kOn3J'><tr id='kOn3J'><dt id='kOn3J'><q id='kOn3J'><span id='kOn3J'><b id='kOn3J'><form id='kOn3J'><ins id='kOn3J'></ins><ul id='kOn3J'></ul><sub id='kOn3J'></sub></form><legend id='kOn3J'></legend><bdo id='kOn3J'><pre id='kOn3J'><center id='kOn3J'></center></pre></bdo></b><th id='kOn3J'></th></span></q></dt></tr></i><div id='kOn3J'><tfoot id='kOn3J'></tfoot><dl id='kOn3J'><fieldset id='kOn3J'></fieldset></dl></div>

      2. Javascript 性能:多个脚本块与单个更大的块

        Javascript Performance: Multiple script blocks Vs single bigger block(Javascript 性能:多个脚本块与单个更大的块)

          <i id='tB3rA'><tr id='tB3rA'><dt id='tB3rA'><q id='tB3rA'><span id='tB3rA'><b id='tB3rA'><form id='tB3rA'><ins id='tB3rA'></ins><ul id='tB3rA'></ul><sub id='tB3rA'></sub></form><legend id='tB3rA'></legend><bdo id='tB3rA'><pre id='tB3rA'><center id='tB3rA'></center></pre></bdo></b><th id='tB3rA'></th></span></q></dt></tr></i><div id='tB3rA'><tfoot id='tB3rA'></tfoot><dl id='tB3rA'><fieldset id='tB3rA'></fieldset></dl></div>
        1. <legend id='tB3rA'><style id='tB3rA'><dir id='tB3rA'><q id='tB3rA'></q></dir></style></legend>
                • <bdo id='tB3rA'></bdo><ul id='tB3rA'></ul>

                    <tbody id='tB3rA'></tbody>
                  <tfoot id='tB3rA'></tfoot>

                  <small id='tB3rA'></small><noframes id='tB3rA'>

                  本文介绍了Javascript 性能:多个脚本块与单个更大的块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 IE8 上观察到了一个奇怪的行为(在 FF 3.5 上没有看到).我创建了 2 个示例网页,其中只有一些 JS.第 1 页:3 个 JS 块(标签),其中包含非常小的内联 JS.第2页:和上面一样的JS,但是所有3个脚本合并在一个块中.

                  I have observed a weird behavior on IE8(not seen on FF 3.5). I created 2 sample web pages with only some JS in it. Page1: 3 JS blocks ( tags) with very small inline JS in them. Page2: Same JS as above, but all 3 scripts combined in one block.

                  我使用 dynatrace 打开页面并观察到对于 page1,每个脚本的解析/执行时间约为 27-30 毫秒.总时间约为 80 毫秒.对于 Page2,合并后的 JS 耗时约 30 毫秒.有人可以解释这背后的原因吗?将较小的 JS 块合并为一个更好吗?

                  I opened the page using dynatrace and observed that for page1, each of the script took ~27-30ms time for parsing/execution. Total time is ~80ms. For Page2, the combined JS took ~30ms. Can someone please explain the reason behind this? Is it better to combine the smaller chunks of JS into one?

                  PS:对于所有脚本,dynatrace 添加的检测时间可以忽略不计.Firefox 3.5 没有表现出这种行为.此外,每个较小的 JS 块在 FF 上的执行时间约为 1 毫秒,而组合 JS 的执行时间约为 3 毫秒.

                  PS: For all the scripts, the instrumentation time added by dynatrace is negligible. Firefox 3.5 did not show this behavior. Also the execution time on FF was ~1ms for each of the smaller JS block and ~3ms for the combined JS.

                  推荐答案

                  当浏览器遇到脚本块时,它必须暂停渲染页面,同时执行该块中的脚本.

                  When a browser encounters a script block it has to pause rendering the page while it executes the script in that block.

                  我不确定为什么 IE8 比 FF 会如此明显.可能是 IE8 中的上下文切换成本特别高,或者 FF 可能会在幕后做一些工作来组合你的块,如果它确定可以的话(我只是在这里猜测)

                  I'm not sure why this would be so pronouced for IE8 over FF. It could be that the context switch is especially costly in IE8, or that FF may do some work behind the scenes to combine your blocks if it determines it can (I'm only guessing here)

                  脚本块也阻止并行下载.如果您从多个主机名下载图像,这可能会并行发生,除非您正在执行脚本块.

                  Script blocks also block parallel downloads. If you're downloading images from multiple hostnames, this can happen in parallel, unless you are executing a script block.

                  一般来说,我认为将脚本块组合起来是最佳做法.就个人而言,我建议您将它们移动到单独的文件中.

                  In general, I would say that it is best practice to combine your script blocks. Personally, I would recommend you move them into a separate file.

                  顺便说一下,当您将指标移到另一个文件时会发生什么情况?

                  Incidentally, what happens with your metrics when you do move it to another file?

                  请参阅 Yahoo Developer 的网站加速最佳实践.

                  See Best Practices for Speeding Up Your Web Site at Yahoo Developer.

                  这篇关于Javascript 性能:多个脚本块与单个更大的块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                  Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                  How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                  How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                  How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                  How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)
                    • <bdo id='tDaYX'></bdo><ul id='tDaYX'></ul>

                        <tbody id='tDaYX'></tbody>
                      <i id='tDaYX'><tr id='tDaYX'><dt id='tDaYX'><q id='tDaYX'><span id='tDaYX'><b id='tDaYX'><form id='tDaYX'><ins id='tDaYX'></ins><ul id='tDaYX'></ul><sub id='tDaYX'></sub></form><legend id='tDaYX'></legend><bdo id='tDaYX'><pre id='tDaYX'><center id='tDaYX'></center></pre></bdo></b><th id='tDaYX'></th></span></q></dt></tr></i><div id='tDaYX'><tfoot id='tDaYX'></tfoot><dl id='tDaYX'><fieldset id='tDaYX'></fieldset></dl></div>

                        <tfoot id='tDaYX'></tfoot>

                        <small id='tDaYX'></small><noframes id='tDaYX'>

                          <legend id='tDaYX'><style id='tDaYX'><dir id='tDaYX'><q id='tDaYX'></q></dir></style></legend>