Skip to content

Instantly share code, notes, and snippets.

@phamann
Last active August 9, 2020 03:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phamann/5441535 to your computer and use it in GitHub Desktop.
Save phamann/5441535 to your computer and use it in GitHub Desktop.
Example of gathering request timing information using the Navigation timing API
function getPerformanceData() {
var perf = window.performance || window.msPerformance || window.webkitPerformance || window.mozPerformance;
if (perf) {
var t = perf.timing;
return [
// Time required for domain lookup.
t.domainLookupEnd - t.domainLookupStart,
// Time to establish a connection to server.
t.connectEnd - t.connectStart,
// From connection established to first byte of data.
t.responseStart - t.connectEnd,
// First byte to last byte, or closed, including if from cache.
t.responseEnd - t.responseStart,
// From last byte of doc to start of domContentLoaded
t.domContentLoadedEventStart - t.responseEnd,
// domcontentLoaded to start of load event.
t.loadEventStart - t.domContentLoadedEventStart,
// click, back/forward, etc...
perf.navigation.type,
// No. of redirects on current domain.
perf.navigation.redirectCount
].join(',');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment