PerformanceResourceTiming: decodedBodySize property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2023.
Note: This feature is available inWeb Workers.
ThedecodedBodySize 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.
In this article
Value
ThedecodedBodySize 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.
0if the resource is a cross-origin request and noTiming-Allow-OriginHTTP response header is used.
Examples
>Checking if content was compressed
If thedecodedBodySize andencodedBodySize properties are non-null and differ, the content was compressed (for example, gzip or Brotli).
Example using aPerformanceObserver, which notifies of newresource performance entries as they are recorded in the browser's performance timeline. Use thebuffered 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 usingPerformance.getEntriesByType(), which only showsresource 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 thedecodedBodySize property is0, the resource might be a cross-origin request. To expose cross-origin content size information, theTiming-Allow-Origin HTTP response header needs to be set.
For example, to allowhttps://developer.mozilla.org to see content sizes, the cross-origin resource should send:
Timing-Allow-Origin: https://developer.mozilla.orgSpecifications
| Specification |
|---|
| Resource Timing> # dom-performanceresourcetiming-decodedbodysize> |