The activationStart
read-only property represents the time between when a document starts prerendering and when it is activated.
A DOMHighResTimeStamp
representing the duration between document prerendering start and activation in milliseconds.
The value is 0
if the page has not prerendered or is still prerendering.
When a prerendered document is activated, activationStart
is set to the current time. The following function can check whether a page is prerendering
or has already prerendered:
function pagePrerendered() {
return (
document.prerendering ||
self.performance?.getEntriesByType?.("navigation")[0]?.activationStart > 0
);
}
With prerendered pages, a page may have been created long before it was actually navigated to. When using the Performance API on prerendered pages, it is vital to compare returned values with activationStart
in order to avoid misleading measurements.
let activationStart =
performance.getEntriesByType("navigation")[0].activationStart;
let firstPaint = performance.getEntriesByName("first-paint")[0].startTime;
let firstContentfulPaint = performance.getEntriesByName(
"first-contentful-paint",
)[0].startTime;
console.log("time to first paint: " + (firstPaint - activationStart));
console.log(
"time to first-contentful-paint: " + (firstContentfulPaint - activationStart),
);