有没有办法与执行分开下载时间脚本?

发布于 2025-02-12 09:54:55 字数 308 浏览 1 评论 0原文

我想为我的主要JavaScript负载启动一些定时变量。我可以做类似的事情:

<script>
  performance.mark('script-start')
</script>
<script src="something.js"></script>

然后在某个地方添加performance.Measure('script-start')

问题在于,这将使脚本下载时间和脚本解析以及(一部分)执行时间计时。有没有办法分别下载和执行脚本?

I'd like to instrument some timing variables for my main JavaScript load. I could do something like this:

<script>
  performance.mark('script-start')
</script>
<script src="something.js"></script>

Then somewhere in something.js add a performance.measure('script-start').

The problem is that this would time both the script download time and the script parsing and (part of) the execution time. Is there a way to time script download and execution separately?

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

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

发布评论

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

评论(1

别低头,皇冠会掉 2025-02-19 09:54:55

performance.measure('script-start')放在something.js的一开始。这将包括解析时间,但不包括执行时间。除非脚本很大,否则解析时间应该几乎可以忽略不计。

您可以通过在第一个&lt; script&gt;标签中将下载和执行时间分别为下载和执行。然后放在

performance.measure('download-end');
performance.start('script-start');

something.js的开头。

Put performance.measure('script-start') at the very beginning of something.js. This will include the parse time, but not the execution time. Unless the script is enormous, the parse time should be almost negligible.

You could time the download and execution separately by putting performance.mark('download-start') in the first <script> tag. Then put

performance.measure('download-end');
performance.start('script-start');

at the beginning of something.js.

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