統計網頁加載時間


Web performance APIs

可以得到各種時間,如dns解析時間,連接時間、跳轉時間、加載時間等指標。
這些API需要在頁面加載完成后才能使用,需要在window.onload事件中讀取各種數據,因為很多值必須在頁面完全加載之后才能得出。

  • 頁面加載API

 

window.performance.timing 返回一個只讀的PerformanceTiming對象,用於分析頁面整體性能指標,常用的統計數據如下:

  • DNS查詢耗時 :domainLookupEnd - domainLookupStart
  • TCP鏈接耗時 :connectEnd - connectStart
  • request請求耗時 :responseEnd - responseStart
  • 解析dom樹耗時 : domComplete- domInteractive
  • 白屏時間 :responseStart - navigationStart
  • domready時間 :domContentLoadedEventEnd - navigationStart
  • onload時間 :loadEventEnd - navigationStart

其中navigationStart為准備加載新頁面的起始時間,loadEventEnd文檔觸發load事件結束時間

  • 資源加載API

window.performance.getEntries() 顯示所有靜態資源的加載時間
window.performance.getEntriesByName() 獲取相應名字資源的加載時間
window.performance.getEntriesByType() 獲取相應類型資源的加載時間

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM