Skip to content

Document policy and image compression

Noted by on his .

Interaction between the Document-Policy *-images-max-bpp directive and a user-agent’s supported image formats is currently unspecified.

Next-gen image formats of the present and future include WebP, AVIF, JPEG-XL, and WebP2. With every new format, new compression ratios become possible; however, cross-browser support is inconsistent. That means possible compression ratios also vary by browser. Fewer supported image formats should allow a less aggressive compression ratio in the Document Policy. Unfortunately, browsers’ Accept request headers don’t always report supported image formats, so servers can’t easily compute the best policy for a given browser.

Specifying a per-mimetype compression ratio isn’t ideal. Sometimes a PNG can beat AVIF or come close enough to not justify the extra bytes of a <picture> element. On a browser with AVIF and PNG support, loaded PNGs should be held to AVIF-level compression expectations.

I think the most robust solution would be to offer multiple image-compression policies to a browser; the browser can then pick the policy that matches its supported image formats. For instance: a server could offer a max-bpp-supports-webp, max-bpp-supports-webp-avif, max-bpp-supports-webp-avif-jxl, etc. Unfortunately, this is really wordy and will only grow more complex as browsers adopt new image formats.

TLDR: in a web where supported image formats can vary, it’s unclear how *-images-max-bpp and a UA’s supported image formats should interact. This variance warrants a policy more complex than a single global value.


This site supports Webmentions, a backlink-based alternative to traditional comment forms.

Publish a response on your own website and share the link here to send me a webmention! Include a link to this page's canonical location for it to be accepted.

Webmentions received for this post appear in the following list after I approve them. I sometimes send Webmentions to myself on behalf of linking sites that don't support them. I replace broken links with Wayback Machine snapshots, if they exist.

Toggle Webmentions

This comment may have major formatting errors that could impact screen reader comprehension.

Oddly, "bpp" in this context stands for "bytes per pixel" and refers to compression ratios rather than color depth. These document policy directives prevent images from loading if they are too big, taking into account their dimensions.

Feel free to contact me directly with feedback; here’s my contact info