NavigationStart time set to 0 when using the HTML5 navigation API

I am using the HTML5 navigation API to measure user expected page load time on my site.

I use the following code to measure page load time.

function recordLoadTime () { /* Process load time using "Navigation Timing" */ if (typeof(window.performance) !== "undefined" && typeof(window.performance.timing) !== "undefined") { if (window.performance.timing.loadEventEnd > 0) { var time = window.performance.timing.loadEventEnd - window.performance.timing.navigationStart; } else { setTimeout(recordLoadTime, 1000); } } } 

The time variable is also added to the cookie and recorded on the server in subsequent user requests.

I ran into a problem when the recorded time is very close to the current time of the era, i.e. navigationStart set to 0, but loadEventEnd has a non-zero value (i.e. the current time of the era)

I saw this behavior in Chrome / 11.0, Chrome / 12.0, MSIE 7.0, MSIE 8.0 and MSIE 9.0

I temporarily solved this by modifying the code above to record load times only when navigationStart greater than 0. But I want to write down load times for all pages served.

+4
source share
1 answer
 window.onload = function() { setTimeout(function(){ var t = performance.timing; }, 0); 
+1
source

All Articles