0
我正在使用Navigation Timing API從頁面獲取加載事件。我已經添加了下面的JS代碼片段來輸出信息。我注意到的一件事很奇怪,當我檢查控制檯時,loadEventEnd
時間早於loadEventStart
時間回來。我認爲這是不可能的。導航計時API事件不按順序觸發
var startTime = new Date().getTime();
// retrieve the performance object in a cross browser way. Check window.performance first.
window.performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {};
var timing = window.performance.timing || {};
var navigation = window.performance.navigation || {};
// if the Navigation Timing API is supported
if (window.performance && window.performance.timing) {
pageRequestStart = timing.requestStart;
pageResponseStart = timing.responseStart;
pageResponseEnd = timing.responseEnd;
pageLoadEventStart = timing.loadEventStart;
pageLoadEventEnd = timing.loadEventEnd;
pageLoadTime = timing.navigationStart;
}
var timingOutput =
"requestStart: " + pageRequestStart + "\n"
+ "responseStart: " + pageResponseStart + "\n"
+ "responseEnd: " + pageResponseEnd + "\n"
+ "loadEventStart: " + pageLoadEventStart + "\n"
+ "loadEventEnd: " + pageLoadEventEnd + "\n"
+ "navigationStart: " + pageLoadTime;
console.log(timingOutput);
這是一貫的,還是隻是一次性? – 2013-05-01 08:43:30