PerformanceResourceTiming: contentEncoding property

Note: This feature is available in Web Workers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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 RFC 1950) with the deflate compression algorithm (defined in RFC 1951).

br

A format using the Brotli algorithm structure (defined in RFC 7932).

zstd

A format using the Zstandard algorithm structure (defined in RFC 8878).

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.

js
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.

js
const dictionaryCompressedResources = performance
  .getEntriesByType("resource")
  .filter(
    (entry) =>
      entry.contentEncoding === "dcb" || entry.contentEncoding === "dcz",
  );
console.log(dictionaryCompressedResources);

Specifications

Specification
Resource Timing
# dom-performanceresourcetiming-contentencoding

Browser compatibility