Skip to content

怎么统计页面的性能指标?

Posted on:2024年9月5日 at 01:27

下面是一些常用的方法和工具:

1. 使用浏览器开发者工具

Chrome DevTools 提供了丰富的性能分析功能:

示例

  1. 打开 Chrome DevTools(按 F12Ctrl+Shift+I)。
  2. 转到 Performance 面板,点击 Record 按钮开始录制性能数据。
  3. 执行页面操作,然后停止录制,查看详细的性能数据。

2. 使用 Web Vitals

Web Vitals 是 Google 提供的性能指标集合,专注于用户体验:

示例

3. 使用性能监控工具

Google PageSpeed Insights:分析页面性能并提供优化建议。它基于 Lighthouse 提供报告。

GTmetrix:提供页面性能分析,包括加载时间、页面大小和请求数量。

4. 使用 Performance API

Performance API 提供了浏览器的低级性能数据,可以用于自定义性能测量:

示例

performance.mark("start");
// 执行某些操作
performance.mark("end");
performance.measure("my-measure", "start", "end");
const measure = performance.getEntriesByName("my-measure")[0];
console.log(`Duration: ${measure.duration}ms`);
原文转自:https://fe.ecool.fun/topic/a043bcc6-f419-471d-a4cb-4e927daaaf3c