Firefox Tomorrow

web api instance property

PerformanceResourceTiming: decodedBodySize property

View on MDN ↗

Available in workers

The decodedBodySize read-only property returns the size (in octets) received from the fetch (HTTP or cache) of the message body after removing any applied content encoding (like gzip or Brotli). If the resource is retrieved from an application cache or local resources, it returns the size of the payload after removing any applied content encoding.

Value

The decodedBodySize property can have the following values:

  • A number representing the size (in octets) received from the fetch (HTTP or cache) of the message body, after removing any applied content encoding.
  • 0 if the resource is a cross-origin request and no Timing-Allow-Origin HTTP response header is used.

Examples

Checking if content was compressed

If the decodedBodySize and encodedBodySize properties are non-null and differ, the content was compressed (for example, gzip or Brotli).

Example using a PerformanceObserver, which notifies of new resource performance entries as they are recorded in the browser’s performance timeline. Use the buffered option to access entries from before the observer creation.

const observer = new PerformanceObserver((list) => {
  list.getEntries().forEach((entry) => {
    const uncompressed =
      entry.decodedBodySize && entry.decodedBodySize === entry.encodedBodySize;
    if (uncompressed) {
      console.log(`${entry.name} was not compressed!`);
    }
  });
});

observer.observe({ type: "resource", buffered: true });

Example using getEntriesByType(), which only shows resource performance entries present in the browser’s performance timeline at the time you call this method:

const resources = performance.getEntriesByType("resource");
resources.forEach((entry) => {
  const uncompressed =
    entry.decodedBodySize && entry.decodedBodySize === entry.encodedBodySize;
  if (uncompressed) {
    console.log(`${entry.name} was not compressed!`);
  }
});

Cross-origin content size information

If the value of the decodedBodySize property is 0, the resource might be a cross-origin request. To expose cross-origin content size information, the Timing-Allow-Origin HTTP response header needs to be set.

For example, to allow https://developer.mozilla.org to see content sizes, the cross-origin resource should send:

Timing-Allow-Origin: https://developer.mozilla.org

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.

See also