Created
January 18, 2016 13:20
-
-
Save LukyVj/f9eb52a71b710af9084e to your computer and use it in GitHub Desktop.
Get page load time
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
<div id="test"><s><span id="time"></span></s> to display <s><span id="num"></span></s> elements</div> |
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
var beforeload = (new Date()).getTime(); | |
function getLoadTime(){ | |
var afterload = (new Date()).getTime(); | |
seconds = (afterload-beforeload) / 1000; | |
var n = document.getElementById('num'); | |
var a = document.getElementById('acc'); | |
var s = document.getElementById('time'); | |
var loadTime = window.performance.timing.domContentLoadedEventEnd-window.performance.timing.navigationStart; | |
n.innerHTML = document.querySelectorAll('selector').length; | |
if (Math.floor(seconds)>=1){ | |
s.innerHTML = Math.floor(seconds) + 'seconds'; | |
} else { | |
s.innerHTML = seconds + 'miliseconds'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment