: Javascript page load time calculation returns negative <script type="text/javascript">//<![CDATA[ // jQuery has already been loaded but this could be equivalent to // a function in <body
<script type="text/javascript">//<![CDATA[
// jQuery has already been loaded but this could be equivalent to
// a function in <body onLoad="">
$(function(){
var iNavStart=performance.timing.navigationStart;
var iNavEnd=performance.timing.loadEventEnd;
var iPageLoad=iNavEnd-iNavStart;
console.dir({'iNavStart',iNavStart});
console.dir({'iNavEnd',iNavEnd});
console.dir({'iPageLoad',iPageLoad});
});
//]]</script>
When the page loads, the console reveals:
iNavStart: 1449594976150
iNavEnd: 0
iPageLoad: -1449594976150
I was expecting this calculation to give me a nice number of milliseconds. Surely iNavEnd shouldn't be 0?
Tested in Chrome 47 and Firefox 42 (both support performance.timing).
Any ideas where I'm going wrong?
More posts by @Cugini213
1 Comments
Sorted by latest first Latest Oldest Best
I believe that Ionut Popa answers this on Stackoverflow in Measuring Site Load Times via performance api:
You need to measure the loadEventEnd after the onload event has finished or else it will be reported as 0, as never happened. (jquery example for attaching to the onload event)
$(window).load(function(){
setTimeout(function(){
window.performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {};
var timing = performance.timing || {};
var parseTime = timing.loadEventEnd - timing.responseEnd;
console.log('Parsetime: ', parseTime);
}, 0);
});
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.