计算和验证到第一个字节的时间(TTFB) [英] Calculating and verifying Time To First Byte (TTFB)

查看:277
本文介绍了计算和验证到第一个字节的时间(TTFB)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为我提供了以下公式来测量到第一个字节的时间(TTFB),到DOM就绪的TTFB和页面加载.

I was given the following formulas to measure Time To First Byte (TTFB), TTFB to DOM Ready and Page Load.

TTFB

window.performance.timing.responseStart - window.performance.timing.navigationStart

TTFB到DOM就绪

window.performance.timing.domComplete - window.performance.timing.navigationStart

页面加载

window.performance.timing.loadEventStart - window.performance.timing.navigationStart

这些公式正确吗?我将如何检查它们?我听说您可以在Firebug的 Network 面板中对其进行度量,但是在获取值方面似乎很麻烦.不确定在Chrome中从何处获取值.

Are these formulas correct? And how would I be able to check them? I've heard you can measure them in Firebug's Network panel, but it seems overall cumbersome in retrieving the values. Not sure where you get the values in Chrome.

那么,如何确定这些测量值?

So, how to determine those measurements?

推荐答案

Firebug实际上使查看这些计时变得非常容易.您只需要在其命令行中执行window.performance.timing,它将显示一个图形并在下面列出所有计时,如下所示:

Firebug actually makes it very easy to see those timings. You just need to execute window.performance.timing in its command line and it will display a graph and lists all timings below like this:

此外,根据 MDN上的描述,我想说您的计算应从fetchStart开始,因为那是浏览器准备使用HTTP请求获取文档的时刻.根据您对 DOM Ready 的定义,该测量的结束时间也可以是domInteractivedomContentLoadedEventStart时间.

Also, according to the description on MDN, I'd say your calculation should start at fetchStart, as that is the moment in time when the browser is ready to fetch the document using an HTTP request. Depending on your definition of DOM Ready the end time of that measurement may also be the domInteractive or domContentLoadedEventStart time.

因此,我想说的是正确的测量值:

So, I'd say the correct measurements would be:

TTFB

window.performance.timing.responseStart - window.performance.timing.fetchStart

TTFB到DOM就绪

window.performance.timing.domInteractive - window.performance.timing.fetchStart

页面加载

window.performance.timing.loadEventStart - window.performance.timing.fetchStart

这篇关于计算和验证到第一个字节的时间(TTFB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆