我们的志愿者还没有将这篇文章翻译为 中文 (简体)。加入我们帮助完成翻译!
您也可以阅读此文章的English (US)版。
The PerformanceResourceTiming
interface enables retrieving and analyzing detailed network timing data regarding the loading of an application's resources. An application can use the timing metrics to determine, for example, the length of time it takes to fetch a specific resource, such as an XMLHttpRequest
, <SVG>
, image, or script.
The interface's properties create a resource loading timeline with high-resolution timestamps
for network events such as redirect start and end times, fetch start, DNS lookup start and end times, response start and end times, etc.. Additionally, the interface extends PerformanceEntry
with other properties which provide data about the size of the fetched resource as well as the type of resource that initiated the fetch.
<div id="interfaceDiagram" style="display: inline-block; position: relative; width: 100%; padding-bottom: 11.666666666666666%; vertical-align: middle; overflow: hidden;"><svg style="display: inline-block; position: absolute; top: 0; left: 0;" viewbox="-50 0 600 70" preserveAspectRatio="xMinYMin meet"><a xlink:href="https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry" target="_top"><rect x="1" y="1" width="160" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="81" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">PerformanceEntry</text></a><polyline points="161,25 171,20 171,30 161,25" stroke="#D4DDE4" fill="none"/><line x1="171" y1="25" x2="201" y2="25" stroke="#D4DDE4"/><a xlink:href="https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming" target="_top"><rect x="201" y="1" width="250" height="50" fill="#F4F7F8" stroke="#D4DDE4" stroke-width="2px" /><text x="326" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">PerformanceResourceTiming</text></a></svg></div>
a:hover text { fill: #0095DD; pointer-events: all;}
Properties
This interface extends the following PerformanceEntry
properties for resource performance entry types by qualifying and constraining them as follows:
-
PerformanceEntry.entryType
Read only - Returns
"resource"
. PerformanceEntry.name
Read only- Returns the resources URL.
PerformanceEntry.startTime
Read only- Returns the
timestamp
for the time a resource fetch started. This value is equivalent toPerformanceEntrry.fetchStart
. PerformanceEntry.duration
Read only- Returns a
timestamp
that is the difference between theresponseEnd
and thestartTime
properties.
The interface also supports the following properties which are listed in the order in which they are recorded for the fetching of a single resource. An alphabetical listing is shown in the navigation, at left.
PerformanceResourceTiming.initiatorType
Read only- A
string
representing the type of resource that initiated the performance entry, as specified inPerformanceResourceTiming.initiatorType
. PerformanceResourceTiming.nextHopProtocol
Read only- A
string
representing the network protocol used to fetch the resource, as identified by the ALPN Protocol ID (RFC7301). PerformanceResourceTiming.workerStart
Read only- If the current context is a
worker
, returns theDOMHighResTimeStamp
immediately before the worker is started that fetches the resource; otherwise zero is returned. PerformanceResourceTiming.redirectStart
Read only- A
DOMHighResTimeStamp
that represents the start time of the fetch which initiates the redirect. PerformanceResourceTiming.redirectEnd
Read only- A
DOMHighResTimeStamp
immediately after receiving the last byte of the response of the last redirect. PerformanceResourceTiming.fetchStart
Read only- A
DOMHighResTimeStamp
immediately before the browser starts to fetch the resource. PerformanceResourceTiming.domainLookupStart
Read only- A
DOMHighResTimeStamp
immediately before the browser starts the domain name lookup for the resource. PerformanceResourceTiming.domainLookupEnd
Read only- A
DOMHighResTimeStamp
representing the time immediately after the browser finishes the domain name lookup for the resource. PerformanceResourceTiming.connectStart
Read only- A
DOMHighResTimeStamp
immediately before the browser starts to establish the connection to the server to retrieve the resource. PerformanceResourceTiming.connectEnd
Read only- A
DOMHighResTimeStamp
immediately after the browser finishes establishing the connection to the server to retrieve the resource. PerformanceResourceTiming.secureConnectionStart
Read only- A
DOMHighResTimeStamp
immediately before the browser starts the handshake process to secure the current connection. PerformanceResourceTiming.requestStart
Read only- A
DOMHighResTimeStamp
immediately before the browser starts requesting the resource from the server. PerformanceResourceTiming.responseStart
Read only- A
DOMHighResTimeStamp
immediately after the browser receives the first byte of the response from the server. PerformanceResourceTiming.responseEnd
Read only- A
DOMHighResTimeStamp
immediately after the browser receives the last byte of the resource or immediately before the transport connection is closed, whichever comes first. PerformanceResourceTiming.transferSize
Read only- A
number
representing the size (in octets) of the fetched resource. The size includes the response header fields plus the response payload body. PerformanceResourceTiming.encodedBodySize
Read only- A
number
representing the size (in octets) received from the fetch (HTTP or cahce), of the payload body, before removing any applied content-codings. PerformanceResourceTiming.decodedBodySize
Read only- A
number
that is the size (in octets) received from the fetch (HTTP or cache) of the message body, after removing any applied content-codings.
Methods
PerformanceResourceTiming.toJSON()
- Returns a
DOMString
that is the JSON representation of thePerformanceResourceTiming
object.
Example
See the example in Using the Resource Timing API.
Specifications
Specification | Status | Comment |
---|---|---|
Resource Timing Level 1 The definition of 'PerformanceResourceTiming' in that specification. |
Candidate Recommendation | Initial definition. |
Browser compatibility
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support. | 43 | (Yes) | 40 | 10 | 30 | No support |
transferSize , encodedBodySize and decodedBodySize |
54 | ? | ? | ? | 41 | ? |
Feature | Android Webview | Chrome for Android | Edge | Firefox Mobile (Gecko) | Firefox OS | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|---|
Basic support. | 43 | 43 | (Yes) | 42 | ? | 10.0 | 30 | No support |
transferSize , encodedBodySize and decodedBodySize |
54 | 54 | ? | ? | ? | ? | 41 | ? |