Created
February 17, 2018 15:41
-
-
Save lennybacon/2dfe0d5547fe0650bb179e7fd068742d to your computer and use it in GitHub Desktop.
An JavaScript illustrating the usage of the W3C Server Timing API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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