本文主要介绍通过performance分析web性能
window.performance允许网页访问某些函数来测量网页和Web应用程序的性能。
window.performance.timing (PerformanceTiming)
返回一个Object,提供了在加载和使用当前页面期间发生的各种事件的性能计时信息。(均为一个无符号long型的毫秒数)
1 |
|
// 常用计算:
DNS查询耗时 :domainLookupEnd - domainLookupStart
TCP链接耗时 :connectEnd - connectStart
request请求耗时 :responseEnd - responseStart
解析dom树耗时 : domComplete - domInteractive
白屏时间 :responseStart - navigationStart
domready时间(用户可操作时间节点) :domContentLoadedEventEnd - navigationStart
onload时间(总下载时间) :loadEventEnd - navigationStart
window.performance.navigation (PerformanceNavigation)
返回一个Object,返回前给定浏览上下文中网页导航的类型和重定向次数
1 |
|
window.performance.memory (memoryInfo)
返回一个Object,返回量化的脚本内存使用率数字
1 |
|
window.performance.mark(“name”)
在浏览器的性能缓冲区中使用给定名称添加一个timestamp(时间戳) 。
1 |
|
window.performance.measure(“name”)
在浏览器性能记录缓存中创建了一个名为时间戳的记录来记录两个特殊标志位(通常称为开始标志和结束标志)。 被命名的时间戳称为一次测量(measure)。
1 |
|
window.performance.getEntriesByType(“mark”)
获取所有的type为”mark”PerformanceEntry对象数组
window.performance.getEntriesByName(“name”)
获取所有的name为”name”的PerformanceEntry对象数组
window.performance.clearMarks()
清除所有mark
window.performance.clearMeasures()
清除所有measure
window.performance.now()
返回一个DOMHighResTimeStamp对象,该对象表示从某一时刻(某一时刻通常是 navigationStart 事件发生时刻)到调用该方法时刻的毫秒数