This specification establishes the server-timing-params for server-timing-param-names dur and desc, both optional.
[Exposed=(Window,Worker)]
interface PerformanceServerTiming {
readonly attribute DOMString name;
readonly attribute DOMHighResTimeStamp duration;
readonly attribute DOMString description;
[Default] object toJSON();
};
When toJSON is called, run [[!WEBIDL]]'s default toJSON operation.
### name attribute
The name attribute MUST return the DOMString value of the server-specified metric name.
### duration attribute
The duration attribute MUST return a double that contains the server-specified metric duration, or value `0.0`.
### description attribute
The description attribute MUST return the DOMString value of the server-specified metric description, or an empty string.
[Exposed=(Window,Worker)]
partial interface PerformanceResourceTiming {
readonly attribute FrozenArray<PerformanceServerTiming> serverTiming;
};
### serverTiming attribute
The serverTiming attribute returns a sequence of PerformanceServerTiming entries.
When processing the response of the current document, set the serverTiming attribute on the newly created `PerformanceNavigationTiming` object to the return value of the server-timing header parsing algorithm
For each resource fetched by the current browsing context, excluding resources fetched by cross-origin stylesheets fetched with no-cors policy, set the serverTiming attribute on the newly created PerformanceResourceTiming object to:
Given a resource timing object, perform the following steps:
The user-agent MUST process Server-Timing header field communicated via a trailer field (see [[!RFC7230]] section 4.1.2) using the same algorithm.
> GET /resource HTTP/1.1
> Host: example.com
< HTTP/1.1 200 OK
< Server-Timing: miss, db;dur=53, app;dur=47.2
< Server-Timing: customView, dc;desc=atl
< Server-Timing: cache;desc="Cache Read";dur=23.2
< Trailer: Server-Timing
< (... snip response body ...)
< Server-Timing: total;dur=123.4
| Name | Duration | Description |
|---|---|---|
| miss | ||
| db | 53 | |
| app | 47.2 | |
| customView | ||
| dc | atl | |
| cache | 23.2 | Cache Read |
| total | 123.4 |
The above header fields communicate six distinct metrics that illustrate all the possible ways for the server to communicate data to the user agent: metric name only, metric with value, metric with value and description, and metric with description. For example, the above metrics may indicate that for `example.com/resource.jpg` fetch:
The application can collect, process, and act on the provided metrics via the provided JavaScript interface:
// serverTiming entries can live on 'navigation' and 'resource' entries
for (const entryType of ['navigation', 'resource']) {
for (const {name: url, serverTiming} of performance.getEntriesByType(entryType)) {
// iterate over the serverTiming array
for (const {name, duration, description} of serverTiming) {
// we only care about "slow" ones
if (duration > 200) {
console.info('Slow server-timing entry =',
JSON.stringify({url, entryType, name, duration, description}, null, 2))
}
}
}
}