diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/performance/clearresourcetimings/index.html | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/performance/clearresourcetimings/index.html')
-rw-r--r-- | files/zh-cn/web/api/performance/clearresourcetimings/index.html | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/performance/clearresourcetimings/index.html b/files/zh-cn/web/api/performance/clearresourcetimings/index.html new file mode 100644 index 0000000000..e67b1cba7b --- /dev/null +++ b/files/zh-cn/web/api/performance/clearresourcetimings/index.html @@ -0,0 +1,85 @@ +--- +title: Performance.clearResourceTimings() +slug: Web/API/Performance/clearResourceTimings +translation_of: Web/API/Performance/clearResourceTimings +--- +<div>{{APIRef("Resource Timing API")}}</div> + +<p>The <strong><code>clearResourceTimings()</code></strong> method removes all {{domxref("PerformanceEntry","performance entries")}} with an {{domxref("PerformanceEntry.entryType","entryType")}} of "<code>resource</code>" 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 {{domxref("Performance.setResourceTimingBufferSize()")}} method.</p> + +<p>{{AvailableInWorkers}}</p> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox"><em>performance</em>.clearResourceTimings(); +</pre> + +<h3 id="Arguments">Arguments</h3> + +<dl> + <dt>void</dt> + <dd> </dd> +</dl> + +<h3 id="Return_Value" name="Return_Value">Return value</h3> + +<dl> + <dt>none</dt> + <dd>This method has no return value.</dd> +</dl> + +<h2 id="Example">Example</h2> + +<pre class="brush: js">function load_resource() { + var image = new Image(); + image.src = "https://developer.mozilla.org/static/img/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!"); +} +</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Resource Timing', '#dom-performance-clearresourcetimings', 'clearResourceTimings()')}}</td> + <td>{{Spec2('Resource Timing')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<div> + + +<p>{{Compat("api.Performance.clearResourceTimings")}}</p> +</div> |