Function: getTimeToFirstByte()
ts
function getTimeToFirstByte(sample): number;Defined in: getTimeToFirstByte.ts:18
Returns the time to first byte of a response, in milliseconds.
When responseStart is a finite number between startTime and the end of the response, the function returns the time from startTime to responseStart. Otherwise the function returns NaN. The time to first byte and the transfer from getTransferDuration add up to duration.
Parameters
sample
A ResourceTiming sample
Returns
number
The time to first byte in milliseconds, or NaN when the sample has no usable responseStart
Example
ts
// 800 ms to the first byte, then a 50 ms transfer.
const timeToFirstByteMs = getTimeToFirstByte({
startTime: 1000,
responseStart: 1800,
duration: 850,
encodedBodySize: 112_000,
})
equal(timeToFirstByteMs, 800)