[关闭]
@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

  1. // 首包时间
  2. first_byte_time = responseStart - navigationStart
  3. // FCP
  4. first_paint = window.chrome.loadTimes().firstPaintTime * 1000 - navigationStart
  5. // FMP
  6. FMP = 最大布局变化时的绘制
  7. // 可交互时间
  8. 一般可采用 DOMContentLoaded 事件完成的时间
  9. // 总时间
  10. 一般采用页面的 load 事件完成的时间

Snipaste_2019-01-24_23-04-47.png-150kB

FMP算法流程:

275881564-5bf52d2c87b4b_articlex.png-123kB

二、性能优化方法

1. 减少 DNS 查询时间
1)DNS 缓存
2)DNS 预读取

2. 减少 TCP 连接时间
1)长连接
2)HTTP 2:多路复用

3. 减少 HTTP 请求时间
HTTP 请求优化

4. 渲染性能优化
渲染性能优化

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注