What is an accurate measure for time to first byte?

1.3k Views Asked by At

When measuring time to first byte using navigation timing api which amongst these is an accurate measure? and Why?

var timing = performance.timing;

var timeToFirstByte = timing.responseStart - timing.fetchStart

or

var timeToFirstByte_a = timing.responseStart - timing.navigationStart
1

There are 1 best solutions below

1
On

It really depends on what you want to measure.

responseStart - navigationStart

If you go from navigationStart, you will be measuring the time for the browser to unload the previous content, set up the new tab, and (if the page is loaded via a redirect) for the redirect to complete. That is added to the time to set up the new connection to your server and for your server to respond and the for the first byte to be received.

responseStart - fetchStart

If you do fetchStart, you'll just be measuring the time from when the request is sent to your server to when the first byte is received. This will include tcp and ssl negotiation.

responseStart - requestStart

If you want from after the connection is set up to the first byte received, you probably want responseStart - requestStart. This won't include browser set up, redirects, or tcp and ssl negotiation.

Source: https://www.w3.org/TR/navigation-timing/