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
It really depends on what you want to measure.
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.
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With