安全上下文
此特征只可用于
安全上下文
(HTTPS),在某些或所有
支持浏览器
.
PerformanceServerTiming
interface surfaces server metrics that are sent with the response in the
Server-Timing
HTTP header.
This interface is restricted to the same origin, but you can use the
Timing-Allow-Origin
header to specify the domains that are allowed to access the server metrics. Note that this interface is only available in secure contexts (HTTPS) in some browsers.
PerformanceServerTiming.description
只读
DOMString
value of the server-specified metric description, or an empty string.
PerformanceServerTiming.duration
只读
0.0
.
PerformanceServerTiming.name
只读
DOMString
value of the server-specified metric name.
PerformanceServerTiming.toJSON()
DOMString
that is the JSON representation of the
PerformanceServerTiming
对象。
Given a server that sends the
Server-Timing
header, for example a node.js server like this:
const http = require('http');
function requestHandler(request, response) {
const headers = {
'Server-Timing': `
cache;desc="Cache Read";dur=23.2,
db;dur=53,
app;dur=47.2
`.replace(/\n/g, '')
};
response.writeHead(200, headers);
response.write('');
return setTimeout(_ => {
response.end();
}, 1000)
};
http.createServer(requestHandler).listen(3000).on('error', console.error);
PerformanceServerTiming
entries are now observable from JavaScript via the
PerformanceResourceTiming.serverTiming
特性:
let entries = performance.getEntriesByType('resource');
console.log(entries[0].serverTiming);
// 0: PerformanceServerTiming {name: "cache", duration: 23.2, description: "Cache Read"}
// 1: PerformanceServerTiming {name: "db", duration: 53, description: ""}
// 2: PerformanceServerTiming {name: "app", duration: 47.2, description: ""}
| 规范 | 状态 | 注释 |
|---|---|---|
|
Server Timing
The definition of 'PerformanceServerTiming' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
PerformanceServerTiming
|
Chrome 65 | Edge ≤79 | Firefox 61 | IE No | Opera 52 | Safari ? | WebView Android 65 | Chrome Android 65 | Firefox Android 61 | Opera Android 47 | Safari iOS ? | Samsung Internet Android 9.0 |
description
|
Chrome 65 | Edge ≤79 | Firefox 61 | IE No | Opera 52 | Safari ? | WebView Android 65 | Chrome Android 65 | Firefox Android 61 | Opera Android 47 | Safari iOS ? | Samsung Internet Android 9.0 |
duration
|
Chrome 65 | Edge ≤79 | Firefox 61 | IE No | Opera 52 | Safari ? | WebView Android 65 | Chrome Android 65 | Firefox Android 61 | Opera Android 47 | Safari iOS ? | Samsung Internet Android 9.0 |
名称
|
Chrome 65 | Edge ≤79 | Firefox 61 | IE No | Opera 52 | Safari ? | WebView Android 65 | Chrome Android 65 | Firefox Android 61 | Opera Android 47 | Safari iOS ? | Samsung Internet Android 9.0 |
toJSON
|
Chrome 65 | Edge ≤79 | Firefox 61 | IE No | Opera 52 | Safari ? | WebView Android 65 | Chrome Android 65 | Firefox Android 61 | Opera Android 47 | Safari iOS ? | Samsung Internet Android 9.0 |
完整支持
不支持
兼容性未知
实验。期望将来行为有所改变。
PerformanceServerTiming