测量页面加载时间
该操作读取 Navigation Timing API,并在控制台输出 DNS、TCP、TTFB 和完整加载时间。
可复制的代码
try {
const nav = performance.getEntriesByType('navigation')[0];
if (nav) {
const round = function (n) { return Math.round(n) + ' ms'; };
console.log('JustZix page timing:');
console.log(' DNS:', round(nav.domainLookupEnd - nav.domainLookupStart));
console.log(' TCP:', round(nav.connectEnd - nav.connectStart));
console.log(' TTFB:', round(nav.responseStart - nav.requestStart));
console.log(' DOM ready:', round(nav.domContentLoadedEventEnd - nav.startTime));
console.log(' Load:', round(nav.loadEventEnd - nav.startTime));
} else {
console.log('JustZix: navigation timing not available');
}
} catch (err) { console.error('JustZix page timing:', err); }
如何使用此示例
- 用上方按钮复制代码。
- 安装 JustZix(2 分钟),在目标页面打开扩展。
- 添加一条匹配该页面的新规则。
- 启用操作面板,在「操作」选项卡中添加按钮并粘贴代码 — 一键运行。
为此示例评分
暂无评分 — 成为第一个。