统计网页加载时间


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