Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The following script shows how a developer can use the PerformanceNavigationTiming interface to obtain accurate timing data related to the navigation of the document:
function init() {
var navigationTiming = performance.getEntriesByType("navigation")[0];
if (window.console) {
console.log("Name: " + navigationTiming.name + "\n" +
"Entry Type: " + navigationTiming.entryType + "\n" +
"Start Time: " + navigationTiming.startTime + "\n" +
"Duration: " + navigationTiming.duration + "\n" +
"Unload: " + (navigationTiming.unloadEventEnd -
navigationTiming.unloadEventStart) + "\n" +
"Redirect: " + (navigationTiming.redirectEnd -
navigationTiming.redirectStart) + "\n" +
"App Cache: " + (navigationTiming.domainLookupStart -
navigationTiming.fetchStart) + "\n" +
"DNS: " + (navigationTiming.domainLookupEnd -
navigationTiming.domainLookupStart) + "\n" +
"TCP: " + (navigationTiming.connectEnd -
navigationTiming.connectStart) + "\n" +
"Request: " + (navigationTiming.responseStart -
navigationTiming.requestStart) + "\n" +
"Response: " + (navigationTiming.responseEnd -
navigationTiming.responseStart) + "\n" +
"Processing: " + (navigationTiming.loadEventStart -
navigationTiming.responseEnd) + "\n" +
"Onload: " + (navigationTiming.loadEventEnd -
navigationTiming.loadEventStart) + "\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment