初探performance.timing API
初探performance.timing API
浏览器新提供的performance接口精确的告诉我们当访问一个网站页面时当前网页每个处理阶段的精确时间(timestamp),以方便我们进行前端分析。
它是浏览器的直接实现,比之前在网页中用js设置Date.time或者cookie来分析网页时间上要精确很多。
以下是w3c提供的performance.timing各阶段api图
暂时的缺点:
Navigation Timing stops at the window.onload event
现代的网站很多是在onload之后再发触发更多的异步请求,而navigation Timing统计却只在window.onload之后就不统计了 。
为什么不在所有的网络请求完成后统计timing呢?
因为要考虑到有些网页有轮询或者长链接的情况。所以情况就复杂了,w3c还在草案阶段。如果你够牛想出好的解决方案,也可以直接发邮件到w3c去,贡献你的一份力量。
为方便查看统计值,自己写了一个简单的统计表插件
performance API 耗时统计
统计点:

readyStart = timing.fetchStart - timing.navigationStart;
redirectTime = timing.redirectEnd - timing.redirectStart;
appcacheTime = timing.domainLookupStart - timing.fetchStart;
unloadEventTime = timing.unloadEventEnd - timing.unloadEventStart;
lookupDomainTime = timing.domainLookupEnd - timing.domainLookupStart;
connectTime = timing.connectEnd - timing.connectStart;
requestTime = timing.responseEnd - timing.requestStart;
initDomTreeTime = timing.domInteractive - timing.responseEnd;
domReadyTime = timing.domComplete - timing.domInteractive; //过早获取时 domComplete有时会是0
loadEventTime = timing.loadEventEnd - timing.loadEventStart;
loadTime = timing.loadEventEnd - timing.navigationStart;//过早获取时 loadEventEnd有时会是0

结果:

console.log('准备新页面时间耗时: ' + readyStart);
console.log('redirect 重定向耗时: ' + redirectTime);
console.log('Appcache 耗时: ' + appcacheTime);
console.log('unload 前文档耗时: ' + unloadEventTime);
console.log('DNS 查询耗时: ' + lookupDomainTime);
console.log('TCP连接耗时: ' + connectTime);
console.log('request请求耗时: ' + requestTime);
console.log('请求完毕至DOM加载: ' + initDomTreeTime);
console.log('解释dom树耗时: ' + domReadyTime);
console.log('load事件耗时: ' + loadEventTime);
console.log('从开始至load总耗时: ' + loadTime);

使用方法:
可以直接在html底部引入performance-min.js
或下载chrome 插件.crx包,
注意事项
由于window.performance.timing还处于w3c完善过程中,当你的网站有异步请求时,请在所有异步请求完成后再点击chrome上的插件按钮,以确保数据正确
效果图:
=======================================================================
js及chrome插件下载地址
github: https://github.com/willian12345/performanceTracer
关于performance timing 未完善功能老外的讨论:http://www.stevesouders.com/blog/2012/10/30/qa-nav-timing-and-post-onload-requests/
==========================
转载处请注明:博客园偷饭猫willian12345@126.com
初探performance.timing API的更多相关文章
- 浏览器性能接口performance.timing说明
原文来自于 https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html 下图描述了该接口的各个时间 ...
- 初探 performance – 监控网页与程序性能
使用 window.performance 提供了一组精确的数据,经过简单的计算就能得出一些网页性能数据. 配合上报一些客户端浏览器的设备类型等数据,就可以实现简单的统计啦! 额,先看下兼容性如何:h ...
- 【转载】利用window.performance.timing进行性能分析
利用window.performance.timing进行性能分析 性能分析... window.performance.timing中相关属性语义: // .navigationStart 准备 ...
- 利用window.performance.timing进行性能分析
性能分析... window.performance.timing中相关属性语义: // .navigationStart 准备加载页面的起始时间 // .unloadEventStart 如果前一个 ...
- performance.timing检测页面加载速度
with(performance){ readyStart = timing.fetchStart - timing.navigationStart; redirectTime = timing.re ...
- 初探.Net Core API 网关Ocelot(一)
一.介绍 Ocelot 是基于.NetCore实现的开源的API网关,支持IdentityServer认证.Ocelot具有路由.请求聚合.服务发现.认证.鉴权.限流熔断等功能,并内置了负载均衡器与S ...
- 使用WebView监控网页加载状况,PerformanceMonitor,WebViewClient生命周期
原理:WebView加载Url完成后,注入js脚本,脚本代码使用W3C的PerformanceTimingAPI, 往js脚本传入一个Android对象(代码中为AndroidObject),在js脚 ...
- 优化关键渲染路径CRP
什么是关键渲染路径? 从收到 HTML.CSS 和 JavaScript 字节到对其进行必需的处理,从而将它们转变成渲染的像素这一过程中有一些中间步骤 浏览器渲染页面前需要先构建 DOM 和 CSSO ...
- Web 动画帧率(FPS)计算
我们知道,动画其实是由一帧一帧的图像构成的.有 Web 动画那么就会存在该动画在播放运行时的帧率.而帧率在不同设备不同情况下又是不一样的. 有的时候,一些复杂或者重要动画,我们需要实时监控它们的帧率, ...
随机推荐
- Map <STL>
map的使用方法: #include <cstdio> #include <map> #include <string> using namespace std; ...
- Android网络通信android-async-http入门
android-async-http入门 门免费链接分享前:http://pan.baidu.com/s/1mg9SvgO 密码:cgg7 API原文:http://loopj.com/android ...
- Python 得到Twitter所有用户friends和followers
CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-29 @author: guaguastd @name: f ...
- 私人定制javascript中数组小知识点(Only For Me)
先上笑话,1.刚看到一个游泳的,想起公司组织去三亚旅游,老板跳海里,各种挣扎,捞上来老板第一句话:我记得我会游泳的啊. 2.媳妇说:老公对不起,我把你新买的自行车撞散架了! 老公:没事宝贝,你若安好, ...
- Robot Framework + appium 启动手机浏览器的两个方法(1)
一.Open Browser启动 使用Selenium2Library的Open Browser方法,例子如下: browser=手机浏览器类型,如chrome 二.Open Application启 ...
- firefox里面title乱码
原文:firefox里面title乱码 昨天 在notepad++里面写得文档里面title里面有中文,即使在文档里面写有charset=’UTF-8’, 但是保存后在firefox运行,浏览器标签标 ...
- bootstrap collapse MVC .net漂亮的折叠List
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta na ...
- 【Unity Shaders】Mobile Shader Adjustment —— 为手机定制Shader
本系列主要參考<Unity Shaders and Effects Cookbook>一书(感谢原书作者),同一时候会加上一点个人理解或拓展. 这里是本书全部的插图.这里是本书所需的代码和 ...
- 接口自动化测试:Thrift框架RPC协议客户端开发
import java.lang.Thread.State;import java.util.Iterator;import java.util.List; import org.apache.thr ...
- python文本文件,生成指定的文件格式
import os import sys import string #在一个特定的模式打开指定的文件,获取文件句柄 def getFileIns(filePath,model): print(&qu ...