W3cubDocs

/Web APIs

Performance: clearResourceTimings() method

The clearResourceTimings() method removes all performance entries with an 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 resourcetimingbufferfull event.

Syntax

js

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.

js

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.

js

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

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
clearResourceTimings 4622–57 12 35 10 3315–44 11 464.4–57 4625–57 35 3314–43 11 5.01.5–7.0

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Performance/clearResourceTimings