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() 获取相应类型资源的加载时间

 

相关文章:

  • 2021-09-16
  • 2021-12-06
  • 2022-02-06
  • 2021-10-11
  • 2021-05-26
  • 2022-12-23
  • 2021-07-01
  • 2021-12-06
猜你喜欢
  • 2021-08-09
  • 2021-08-07
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2021-09-21
  • 2021-12-06
相关资源
相似解决方案