Performance API
The contentEncoding read-only property of the PerformanceResourceTiming interface is a string indicating the content encoding of the fetched resource.
The content type is extracted from the Content-Encoding HTTP header sent in the resource's fetch response.
Value
A string indicating the content-encoding of the content. This may be one of the following values:
gzip- : A format using the Lempel-Ziv coding (LZ77), with a 32-bit CRC.
This is the original format of the UNIX gzip program.
The HTTP/1.1 standard also recommends that the servers supporting this content-encoding should recognize
x-gzipas an alias, for compatibility purposes.
- : A format using the Lempel-Ziv coding (LZ77), with a 32-bit CRC.
This is the original format of the UNIX gzip program.
The HTTP/1.1 standard also recommends that the servers supporting this content-encoding should recognize
compress- : A format using the Lempel-Ziv-Welch (LZW) algorithm. The value name was taken from the UNIX compress program, which implemented this algorithm. Like the compress program, which has disappeared from most UNIX distributions, this content-encoding is not used by many browsers today, partly because of a patent issue (it expired in 2003).
deflatebr- : A format using the Brotli compression algorithm structure (defined in ).
zstd- : A format using the Zstandard compression algorithm structure (defined in ).
dcb- : A format that uses the Dictionary-Compressed Brotli algorithm. See Compression Dictionary Transport.
dcz- : A format that uses the Dictionary-Compressed Zstandard algorithm. See Compression Dictionary Transport.
Examples
Filtering resources
The contentEncoding property can be used to get specific resource timing entries only; for example, only those related to Compression Dictionary Transport.
The following example uses a PerformanceObserver to notify of new resource performance entries as they are recorded in the browser's performance timeline.
The buffered option is used for accessing entries from before the observer creation.
const observer = new PerformanceObserver((list) => {
const dictionaryCompressedResources = list
.getEntries()
.filter(
(entry) =>
entry.contentEncoding === "dcb" || entry.contentEncoding === "dcz",
);
console.log(dictionaryCompressedResources);
});
observer.observe({ type: "resource", buffered: true });
The following example uses Performance.getEntriesByType(), which only shows resource performance entries present in the browser's performance timeline at the time you call the method.
const dictionaryCompressedResources = performance
.getEntriesByType("resource")
.filter(
(entry) =>
entry.contentEncoding === "dcb" || entry.contentEncoding === "dcz",
);
console.log(dictionaryCompressedResources);
Specifications
Browser compatibility
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
