Created
April 23, 2015 11:54
-
-
Save tkadlec/7e352b74b1961a3e36d7 to your computer and use it in GitHub Desktop.
Super simple example of adding perf timing to the page display during dev work
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
(function () { | |
var perfBar = function(budget) { | |
window.onload = function() { | |
window.performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {}; | |
var timing = window.performance.timing, | |
now = new Date().getTime(), | |
output, loadTime; | |
if (!timing) { | |
//fail silently | |
return; | |
} | |
budget = budget ? budget : 1000; | |
var start = timing.navigationStart; | |
var results = document.createElement('div'); | |
results.setAttribute('id', 'results'); | |
loadTime = now - start; | |
results.innerHTML = (now - start) + "ms"; | |
if (loadTime > budget) { | |
results.className += ' overBudget'; | |
} else { | |
results.className += ' underBudget'; | |
} | |
document.body.appendChild(results); | |
} | |
}; | |
window.perfBar = perfBar; | |
}()); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment