PerformanceServerTiming: description 屬性
注意:此功能在 Web Workers 中可用。
只讀屬性 description 返回一個字串值,表示伺服器指定的指標描述,如果沒有則返回空字串。
值
字串。
示例
記錄伺服器計時條目
伺服器計時指標需要伺服器傳送 Server-Timing 標頭。例如:
http
Server-Timing: cache;desc="Cache Read";dur=23.2
serverTiming 條目可以存在於 navigation 和 resource 條目上。
使用 PerformanceObserver 的示例,它會在 navigation 和 resource 效能條目被記錄到瀏覽器效能時間線上時通知。使用 buffered 選項可以訪問觀察者建立之前的條目。
js
const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
entry.serverTiming.forEach((serverEntry) => {
console.log(
`${serverEntry.name} (${serverEntry.description}) duration: ${serverEntry.duration}`,
);
// Logs "cache (Cache Read) duration: 23.2"
});
});
});
["navigation", "resource"].forEach((type) =>
observer.observe({ type, buffered: true }),
);
使用 Performance.getEntriesByType() 的示例,它僅顯示在呼叫此方法時存在於瀏覽器效能時間線中的 navigation 和 resource 效能條目。
js
for (const entryType of ["navigation", "resource"]) {
for (const { name: url, serverTiming } of performance.getEntriesByType(
entryType,
)) {
if (serverTiming) {
for (const { name, description, duration } of serverTiming) {
console.log(`${name} (${description}) duration: ${duration}`);
// Logs "cache (Cache Read) duration: 23.2"
}
}
}
}
規範
| 規範 |
|---|
| 伺服器計時 # dom-performanceservertiming-description |
瀏覽器相容性
載入中…