Skip to content

Instantly share code, notes, and snippets.

@lxfontes
Created December 14, 2013 02:05
Show Gist options
  • Select an option

  • Save lxfontes/7954804 to your computer and use it in GitHub Desktop.

Select an option

Save lxfontes/7954804 to your computer and use it in GitHub Desktop.
browser timing events
(function() {
if(window.chrome) {
setTimeout(function(){
var timing = window.performance.timing;
var pairs = ['connect',
'domContentLoadedEvent',
'loadEvent',
'domainLookup',
'response',
'unloadEvent'
];
var metrics = {
'requestStart': null,
'fetchStart': null,
'secureConnectionStart': null,
'navigationStart': null,
'domComplete': null,
'domLoading': null,
};
for(var i in metrics) {
metrics[i] = timing[i];
}
for(var i in pairs) {
var pname = pairs[i];
metrics[pname] = timing[pname + 'End'] - timing[pname + 'Start'];
}
metrics['processingTime'] = timing['responseStart'] - timing['requestStart'];
metrics['loadTime'] = timing['domContentLoadedEventEnd'] - timing['navigationStart'];
console.log(metrics);
}, 3000);
// 3 seconds works as a max timeout.
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment