Skip to content

Instantly share code, notes, and snippets.

@lennybacon
Created February 17, 2018 15:41
Show Gist options
  • Save lennybacon/2dfe0d5547fe0650bb179e7fd068742d to your computer and use it in GitHub Desktop.
Save lennybacon/2dfe0d5547fe0650bb179e7fd068742d to your computer and use it in GitHub Desktop.
An JavaScript illustrating the usage of the W3C Server Timing API
if(!window.performance){
document.writeln('<div class="alert alert-danger">Your browser does NOT the Performance API</div>');
} else {
loopServerTiming: for (const entryType of ['navigation', 'resource']) {
for (const {name: url, serverTiming} of performance.getEntriesByType(entryType)) {
if(!serverTiming){
document.writeln('<div class="alert alert-danger">Your browser does NOT the Server Timing API</div>');
break loopServerTiming;
}
for (const {name, duration, description} of serverTiming) {
document.writeln(
'<div class="alert ' + (duration > 100 ? 'alert-danger' : 'alert-success') + '" role="alert">' +
'<h5>' + description + ' <span class="badge badge-secondary">' + duration + 'ms.</span></h5>'+
'<small>' + url + '</small>' +
'</div>'
);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment