高级前端html【Q461】如何计算白屏时间和首屏时间

如何计算白屏时间和首屏时间

Issue 欢迎在 Gtihub Issue 中回答此问题: Issue 469

Author 回答者: hhhpw

白屏时间: window.performance.timing.domLoading - window.performance.timing.navigationStart

首屏时间: window.performance.timing.domInteractive - window.performace.timing.navigationStart

Author 回答者: wuyuehui

首屏时间: window.performance.timing.domInteractive - window.performace.timing.navigationStart

window.performace.timing.navigationStart

performace -> performance少了个n

Author 回答者: kurodasense

参考文献:https://juejin.cn/post/7166244278551707656#heading-9 performance.timing已经被废弃了,需要使用PerformanceNavigationTiming来计算,其获取可以用:

  • window.performance.getEntriesByType(navigation)[0]
  • window.performance.getEntries()[0]