大网数据广告活动
Web 标准与前端开发

PerformanceResourceTiming: contentEncoding property

· 52CE 我爱测

The **`contentEncoding`** read-only property of the PerformanceResourceTiming interface is a string indicating the content encoding of the fetched resource.

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-gzip as an alias, for compatibility purposes.
  • 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).
  • deflate
    • : Using the zlib structure (defined in ) with the deflate compression algorithm (defined in ).
  • br
    • : A format using the Brotli compression algorithm structure (defined in ).
  • zstd
    • : A format using the Zstandard compression algorithm structure (defined in ).
  • dcb
  • dcz

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。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。