大网数据广告活动
Web 标准与前端开发

Performance: clearResourceTimings() method

· 52CE 我爱测

The **`clearResourceTimings()`** method removes all performance entries with an PerformanceEntry.entryType of `"resource"` from the browser's performance timeline and sets the size of the performance resource data buffer to zero.

Performance API

The clearResourceTimings() method removes all performance entries with an PerformanceEntry.entryType of "resource" from the browser's performance timeline and sets the size of the performance resource data buffer to zero.

To set the size of the browser's performance resource data buffer, use the Performance.setResourceTimingBufferSize() method.

To get notified when the browser's resource timing buffer is full, listen for the Performance.resourcetimingbufferfull_event event.

Syntax

clearResourceTimings()

Parameters

None.

Return value

None (undefined).

Examples

Clearing the performance resource data buffer

To remove all resource performance entries from the buffer, call the clearResourceTimings() at an appropriate point in your code or paste it into the console.

performance.clearResourceTimings();
performance.getEntriesByType("resource").length; // 0

Taking records and emptying performance observers

When using PerformanceObserver objects (especially with the buffered flag set to true), the performance resource buffer might get full quickly. However, instead of clearing the buffer, you can also store the current list of performance entries and empty the performance observer using the PerformanceObserver.takeRecords() method. This works with all kinds of performance entry types, not just "resource" entries.

function perfObserver(list, observer) {
  list.getEntries().forEach((entry) => {
    // do something with the entries
  });
}
const observer = new PerformanceObserver(perfObserver);
observer.observe({ type: "resource", buffered: true });

// Store entries and empty performance observer
const records = observer.takeRecords();

Specifications

Browser compatibility

See also

  • Performance.setResourceTimingBufferSize()
  • Performance.resourcetimingbufferfull_event

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。