Data Start Time
Data start time is an important web performance metric that is calculated from timing points made available through the W3C Navigation Timing API.
It is calculated as the difference between the `responseStart` and `navigationStart`or `fetchStart` timing point attributes of the API. The `navigationStart` attribute returns the time immediately after the user agent finishes prompting to unload the previous document, if it exists. If there is no previous document, then the `fetchStart` timing point is used as this signifies when the user agent (browser) begins to check local application caches or the time it starts to fetch the resource. The `responseStart` attribute is the time immediately after the browser receives the first byte of the response from either the server, from any relevant application caches, or from any other local resources.
From this definition, data start time represents the time to first byte (TTFB), a term by which data start time is also known as.
The metric comprises of several component parts. The primary components include DNS lookup, TCP connection, TLS negotiation, the server time necessary to build and serve the request resource and the network time to deliver the first packet back to the browser.
For the HTML document request, data start time has a direct impact on how quickly a web page can begin rendering to the viewport as the browser activities involved in building the web page cannot begin before the HTML stream has been fully received.
Data start time is applicable to all resources loaded by the HTML stream and each resource will also record a separate data start time as they connect to their appropriate server to receive the request resource. However, some resources may not need to complete DNS, TCP and TLS connection as they are using existing connection, so data start time will consist of time on the server infrastructure and network latency.
Therefore as data start time is pervasive for all web page resources it is important to ensure that it is kept to a minimum.
Where no document exists previously, such as in a new browser instance:
dataStartTime = window.performance.timing.responseStart - window.performance.timing.fetchStart ;
Where a document exists previously in the browser:
dataStartTime = window.performance.timing.responseStart - window.performance.timing.navigationStart ;
let perfEntries = performance.getEntriesByType("navigation");
dataStartTime = perfEntries.responseStart - perfEntries.fetchStart;
The resultant dataStartTime values are given in milliseconds.