window.performance参数详细解析

网页性能监测详解
本文深入讲解了网页性能监测的关键指标,包括performance API的各种方法和属性,如performance.mark(), performance.now(), 以及PerformanceTiming对象的详细属性说明,帮助开发者理解如何测量和优化网页加载速度。
方法
 

performance.mark( )  从navigetionStart事件发生时刻到记录时刻间隔的毫秒数
 
performance.now( ) 从navigetionStart事件发生时刻到调用该方法间隔的毫秒数
 
 
属性
 

performance.timing  是一个PerformanceTiming 对象,包含延迟相关的性能消息。
 
performance.navigation 是一个  PerformanceTiming 对象,表示在当前给定浏览上下文中网页导航的类型
 
 
performance.timing(单位:毫秒)
 

PerformanceTiming.navigationStart  
表征了从同一个浏览器上下文的上一个文档卸载结束时的UNIX时间戳,如果没有上一个文档,这个值和PerformanceTiming.fetchStart相同
 
PerformanceTiming.unloadEventStart
表征了unload事件抛出时的UNIX时间戳。如果没有上一个文档,这个值返回0
 
PerformanceTiming.unloadEventEnd
表征了unload事件处理完成时的UNIX时间戳。如果没有上一个文档,这个值返回0
 
PerformanceTiming.redirectStart
表征了HTTP重定向开始时的UNIX时间戳。如果没有重定向,或者重定向中的一个不同源,这个值返回0
 
PerformanceTiming.redirectEnd
表征了unload事件处理完成时(HTTP响应的最后一个比特直接被收到)的UNIX时间戳。如果没有重定向,或者重定向中的一个不同源如果没有上一个文档,这个值返回0
 
PerformanceTiming.fetchStart
表征了浏览器准备好使用HTTP请求来获取(fetch)文档的UNIX时间戳。这个时间点会在检查任何应用缓存之前
 
PerformanceTiming.domainLookupStart
表征了域名查询开始的UNIX时间戳,如果建立了持久连接,或者这个信息存储到了缓存或者本地资源上,这个值和PerformanceTiming.fetchStart相同
 
PerformanceTiming.domainLookupEnd
表征了域名查询结束的UNIX时间戳,如果建立了持久连接,或者这个信息存储到了缓存或者本地资源上,这个值和PerformanceTiming.fetchStart相同
 
PerformanceTiming.connectStart
返回了HTTP请求开始向服务器发送时的UNIX时间戳,如果建立了持久连接,这个值和PerformanceTiming.fetchStart相同
 
PerformanceTiming.connectEnd
返回了HTTP与服务器连接建立(所有的握手和认证过程全部结束)时的UNIX时间戳,如果建立了持久连接,这个值和PerformanceTiming.fetchStart相同
 
PerformanceTiming.secureConnectionStart
返回浏览器与服务器开始安全链接时的握手时的UNIX时间戳。如果当前网页不要求安全连接,则返回0
 
PerformanceTiming.requestStart
返回浏览器向服务器发出HTTP请求时(或者开始读取本地缓存时)的UNIX时间戳
 
PerformanceTiming.responceStart
返回浏览器从服务器收到(或者本地缓存/本地资源读取时)第一个字节的UNIX时间戳。如果传输层在开始请求之后失败并且连接被重开,该属性会成为新的请求的相对应的发起时间
 
PerformanceTiming.responceEnd
返回浏览器从服务器收到(或者本地缓存/本地资源读取时)最后一个字节(如果在此之前HTTP连接已经关闭,则返回关闭时)的UNIX时间戳。
 
PerformanceTiming.domLoading
返回当前网页DOM结构开始解析时(即Document.readyState属性变为‘loading’、相应的readystatechange事件触发时)的UNIX时间戳。
 
PerformanceTiming.domInteractive
返回当前网页DOM结构解析结束,开始加载内嵌资源时(即Document.readyState属性变为‘interactive’、相应的readystatechange事件触发时)的UNIX时间戳。
 
PerformanceTiming.domContentLoadedEventStart
返回当解析器发送DOMContentLoaded事件,即所有需要被执行的脚本开始被解析时的UNIX时间戳。
 
PerformanceTiming.domContentLoadedEventEnd
返回当解析器发送DOMContentLoaded事件,即所有需要被执行的脚本已经被解析完毕时的UNIX时间戳。
 
PerformanceTiming.domComplete
返回当前文档解析完成,即Document.readyState变为'Complete',对应的readystatechange 被触发时的UNIX时间戳。
 
PerformanceTiming.loadEventStart
表征了load事件抛出时的UNIX时间戳。如果这个事件还未发送,这个值返回0
 
PerformanceTiming.loadEventEnd
表征了load事件处理完成时的UNIX时间戳。如果这个事件还未发送,或者尚未完成,这个值返回
 
 
 

转载于:https://www.cnblogs.com/canulook/p/9996347.html

const largeObjectArray = this.createLargeObjectArray(); const newWatch = (callback) =>{ // table 打印时间 const tablePrintTime = this.calculateTime(() => { console.table(largeObjectArray); }); // 普通输出时间 const printLogTime = this.calculateTime(() => { console.log(largeObjectArray); }); // 有效时间检测(排除0值) if (tablePrintTime > 0 && printLogTime > 0) { // 动态阈值判断(当前值对比) if (tablePrintTime > printLogTime * 10) { console.log('时间对比新', tablePrintTime, printLogTime); callback(true); return; } } callback(false); }addListener(function(isOpen) { if (isOpen) { if ( document.body.innerHTML.indexOf('检测到非法调试,即将关闭此页面') < 0 ) { newWatch((isDetected) => { console.log('是什么', isDetected) if (isDetected) { document.body.innerHTML = '检测到非法调试,即将关闭此页面!'; alert('检测到非法调试,即将关闭此页面!'); window.location.href = 'about:blank'; if (window.history.replaceState) { window.history.replaceState( null, '', window.location.pathname + window.location.search, ); } } }); } } }); // 开始检测 launch(); // 禁用开发者工具 createLargeObject() { // 新 if (!this._largeObject) { this._largeObject = Array.from({length: 500}, (_, i) => ({ key: i, value: `${i}` }) ); } return this._largeObject; } // 创建大对象数组 createLargeObjectArray() { // 新 return Array(50).fill(this.createLargeObject()); } // 计算打印执行时间 calculateTime(func) { //新 const start = performance.now(); // 改用高精度时间 func(); return performance.now() - start; }以上代码在ie执行会报错么
03-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值