deniz.in

Markets

Weather

Loading weather

· via dev.to (home feed)

AVIF-first picture markup cut image bytes 56% in Chromium, Firefox and WebKit test

A dev.to experiment across Chromium, Firefox and WebKit confirms browsers download exactly one file from a picture element, with AVIF saving 56.2% over JPEG — if the sources are ordered correctly.

AVIF-first picture markup cut image bytes 56% in Chromium, Firefox and WebKit test

A cross-browser experiment published on dev.to set out to answer a deceptively simple question: when a page uses the picture element with multiple image formats, which file does the browser actually download? The answer, measured across three engines, was consistent — and it came with two gotchas that quietly cost developers bytes.

One image, one request

According to the dev.to write-up, the author — who builds the Blinkimg image service and discloses that an AI assistant ran the measurement code on their machine — produced three versions of a single 4964 × 2782 camera photo, resized to 1280 pixels wide: a mozjpeg q80 file at 79,671 bytes, a WebP q75 file at 46,384 bytes and an AVIF q50 file at 34,898 bytes. Pages were served from a local Node server that logged every response, with browsers driven by Playwright 1.61.1.

Chromium 149, Firefox 151 and WebKit 26.5 all behaved identically: they walked the source children in order, took the first one whose type they supported, and made exactly one image request. When the AVIF source came first, every engine fetched the 34,898-byte AVIF — 44,773 bytes, or 56.2%, less than the JPEG fallback. The author notes this matches MDN's documentation of the picture element: unsupported types are skipped, and the img tag is the fallback of last resort.

Source order silently changes the bytes

The sharpest finding is that source order matters and nothing warns you. When the author swapped the markup so the WebP source came before the AVIF one, every browser took the WebP and never requested the AVIF at all. That reordering cost 11,486 extra bytes — 32.9% more than the AVIF file — with no error, no console message and no visible difference. The practical rule from the article: list the smallest supported format first.

The type attribute is a promise, not a hint

Because all three installed engines support AVIF, the author simulated an unsupported format with an invented MIME type. Faced with two sources of fake types, all three browsers skipped both and downloaded the JPEG — and issued no requests for the skipped files. An older browser without AVIF support behaves the same way with a real AVIF source, so fallback costs nothing extra on the network.

The article also documents a nastier failure mode. The type attribute is treated as a promise about the file: if a browser supports the declared type and the file is missing, there is no fallback. The author put a source typed as image/jxl first, pointing at a nonexistent file. Chromium and Firefox, which do not support that type, skipped it and loaded the AVIF. WebKit 26.5, which matched the type, requested the missing file and rendered nothing — naturalWidth was 0 — and the JPEG fallback never ran.

Omitting the type attribute is no safer. Without it, a browser cannot skip a source by format; it only skips on media conditions or decode failure. A type-less AVIF source worked in this test only because every engine tested decodes AVIF — on one that cannot, the result would be a broken image rather than a JPEG.

Savings grow with image width

The author generated all three formats at five widths from the same photo, and AVIF was smallest every time: 4,656 bytes at 320 px versus 9,589 for JPEG, rising to 66,799 bytes at 1920 px versus 153,394 for JPEG. The absolute gap widens with size — 4,933 bytes saved at 320 px, 86,595 at 1920 px. The author cautions that AVIF at q50 is not visually identical to JPEG at q80 for every photo, and that byte counts ignore decode cost on weak hardware, which the test did not measure.

Why it matters

Images usually dominate page weight, and the picture element is the standard mechanism for serving modern formats with safe fallbacks. This test quantifies the payoff — roughly half the bytes at typical widths, in all three major engines — and exposes the two mistakes that erase it: ordering sources so a larger format wins by default, and misdeclaring a source so a missing file becomes a broken image instead of a graceful fallback. The article's checklist is short: AVIF first, WebP second, JPEG in the img fallback; a correct type on every source; explicit width and height on the img; and every referenced file actually deployed. To verify what loaded, read the img element's currentSrc property in the console. The findings come from a single photo at specific quality settings, tested without CDNs, caching or slow networks, so the percentages are indicative rather than universal — but the source-order and fallback behavior held identically across all three engines.

  • #avif
  • #webp
  • #html
  • #image-optimization
  • #web-performance