performance.clearResourceTimings() - Web APIs 编辑
The clearResourceTimings()
method removes all performance entries
with an entryType
of "resource
" from the browser's performance data buffer and sets the size of the performance data buffer to zero. To set the size of the browser's performance data buffer, use the Performance.setResourceTimingBufferSize()
method.
Note:
This feature is available in Web Workers.Syntax
performance.clearResourceTimings();
Arguments
- void
Return value
- none
- This method has no return value.
Example
function load_resource() {
var image = new Image();
image.src = "https://www.wenjiangs.com/wp-content/uploads/2020/mozilla/opengraph-logo.png";
}
function clear_performance_timings() {
if (performance === undefined) {
log("Browser does not support Web Performance");
return;
}
// Create a resource timing performance entry by loading an image
load_resource();
var supported = typeof performance.clearResourceTimings == "function";
if (supported) {
console.log("Run: performance.clearResourceTimings()");
performance.clearResourceTimings();
} else {
console.log("performance.clearResourceTimings() NOT supported");
return;
}
// getEntries should now return zero
var p = performance.getEntriesByType("resource");
if (p.length == 0)
console.log("... Performance data buffer cleared");
else
console.log("... Performance data buffer NOT cleared!");
}
Specifications
Specification | Status | Comment |
---|---|---|
Resource Timing Level 1 The definition of 'clearResourceTimings()' in that specification. | Candidate Recommendation | Initial definition. |
Browser compatibility
BCD tables only load in the browser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论