1.使用Google Analytics
包含了性能統(tǒng)計,暫時沒用過。
2.Web performance APIs
可以得到各種時間,如dns解析時間,連接時間、跳轉(zhuǎn)時間、加載時間等指標(biāo)。
這些API需要在頁面加載完成后才能使用,需要在window.onload事件中讀取各種數(shù)據(jù),因為很多值必須在頁面完全加載之后才能得出。
-
頁面加載API
window.performance.timing 返回一個只讀的PerformanceTiming對象,用于分析頁面整體性能指標(biāo),常用的統(tǒng)計數(shù)據(jù)如下:- DNS查詢耗時 :domainLookupEnd - domainLookupStart
- TCP鏈接耗時 :connectEnd - connectStart
- request請求耗時 :responseEnd - responseStart
- 解析dom樹耗時 : domComplete- domInteractive
- 白屏?xí)r間 :responseStart - navigationStart
- domready時間 :domContentLoadedEventEnd - navigationStart
- onload時間 :loadEventEnd - navigationStart
其中navigationStart為準(zhǔn)備加載新頁面的起始時間,loadEventEnd文檔觸發(fā)load事件結(jié)束時間
資源加載API
window.performance.getEntries() 顯示所有靜態(tài)資源的加載時間
window.performance.getEntriesByName() 獲取相應(yīng)名字資源的加載時間
window.performance.getEntriesByType() 獲取相應(yīng)類型資源的加載時間