性能计时API不一致

时间:2018-11-29 19:14:44

标签: javascript performance api navigation

我正在尝试使用navigaiton API跟踪网页加载页面所花费的时间。我打算使用以下公式

网络时间=(responseEnd – fetchStart)–(responseStart – requestStart)。(responseStart – requestStart)是服务器在收到请求后向浏览器发送响应的第一个字节所花费的时间。我对API的理解正确吗?

此外,当我尝试获取这些数据时,直到responseEnd为止,我得到的所有值都相同。

window.onload = function(){  
    setTimeout(function(){
        console.log("navigationStart : "+ (performance.timing.navigationStart));
        console.log("fetchStart: "+ (performance.timing.fetchStart));
        console.log("requestStart: "+  (performance.timing.requestStart));       
        console.log("responseStart : "+ (performance.timing.responseStart));       
        console.log("responseEnd : "+ (performance.timing.responseEnd));       
        console.log("domComplete : "+ (performance.timing.domComplete));       
        console.log("loadEventStart : "+ (performance.timing.loadEventStart));       
        console.log("LoadEventEnd : "+ (performance.timing.loadEventEnd));      
        console.log("now: "+ (Date.now()));
        console.log("frame count is "+ (frames.length));
    }, 0);
}

下面是输出

navigationStart : 1543517910446
fetchStart: 1543517910446
requestStart: 1543517910446
responseStart : 1543517910446
responseEnd : 1543517910446
domComplete : 1543517912670
loadEventStart : 1543517912670
LoadEventEnd : 1543517912908
now: 1543517912936
frame count is 0

0 个答案:

没有答案