@Sakura-W
2019-01-25T08:08:07.000000Z
字数 1073
阅读 740
技术分享
1. 性能指标
The primary difference between the two metrics is FP marks the point when the browser renders anything that is visually different from what was on the screen prior to navigation. By contrast, FCP is the point when the browser renders the first bit of content from the DOM, which may be text, an image, SVG, or even a element.
FP 事件在图层进行绘制的时候触发,FCP 是文本、图片或 Canvas 出现的时候触发
The most important rule of performance measurement code is that it shouldn't make performance worse.
2. 统计方式
主要利用 window.performance.timing 这个浏览器提供的 api
// 首包时间
first_byte_time = responseStart - navigationStart
// FCP
first_paint = window.chrome.loadTimes().firstPaintTime * 1000 - navigationStart
// FMP
FMP = 最大布局变化时的绘制
// 可交互时间
一般可采用 DOMContentLoaded 事件完成的时间
// 总时间
一般采用页面的 load 事件完成的时间
FMP算法流程:
1. 减少 DNS 查询时间
1)DNS 缓存
2)DNS 预读取
2. 减少 TCP 连接时间
1)长连接
2)HTTP 2:多路复用
3. 减少 HTTP 请求时间
HTTP 请求优化
4. 渲染性能优化
渲染性能优化