Skip to content

Instantly share code, notes, and snippets.

@jasonday
Created January 5, 2016 21:13
Show Gist options
  • Save jasonday/f4e62712dd7bc8e32304 to your computer and use it in GitHub Desktop.
Save jasonday/f4e62712dd7bc8e32304 to your computer and use it in GitHub Desktop.
// perf stats
function getPerfStats() {
var timing = window.performance.timing;
var resourceList = window.performance.getEntriesByType("resource");
var ajaxReq = [];
for (i = 0; i < resourceList.length; i++) {
if (resourceList[i].initiatorType == "xmlhttprequest") {
ajaxReq.push({
name: resourceList[i].name,
time: resourceList[i].responseEnd - resourceList[i].startTime
});
}
}
var results = {
ttfb: (timing.responseStart - timing.connectEnd) / 1000 + "s",
domInteractive: (timing.domInteractive - timing.navigationStart) / 1000 + "s",
domComplete: (timing.loadEventStart - timing.navigationStart) / 1000 + "s",
loadEvent: (timing.loadEventEnd - timing.navigationStart) / 1000 + "s",
ajax: ajaxReq
};
return results;
}
if (window.performance && window.performance.timing) {
getPerfStats();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment