Network & PerformanceBaseline · Widely

Responsive Images & Decoding

Mental Model

srcset and sizes let the browser pick the smallest sharp image before layout runs. Add width and height to reserve space against CLS, fetchpriority="high" on the hero LCP image, and decoding="async" on offscreen images to keep bitmap decompression off the main thread.

Interactive Simulator

Hero LCP Image: Naive <img> vs Prioritized Responsive <img>

Compare a lazy-loaded un-sized <img> against a fetchpriority=high, intrinsic-sized responsive image.

Lines of Code
Before
5
After
6
Reflows / Browser Cost
Before
CLS 0.24 (no aspect ratio)
After
CLS 0.00 (intrinsic aspect ratio)
BeforeNaive <img> (Delayed LCP + Layout Shift)
<img
  src="/hero-2400w.jpg"
  loading="lazy"
  alt="Product hero"
/>
Lines: 5Reflows: CLS 0.24 (no aspect ratio)Dependencies: Delayed until layout + main-thread decode

Lazy loading stalls LCP discovery; missing width/height shifts content on load.

After (Native)Prioritized Responsive <img> (Fast LCP, Zero CLS)
<img
  src="/hero-800w.avif" srcset="/hero-800w.avif 800w, /hero-1600w.avif 1600w"
  sizes="(max-width: 768px) 100vw, 800px"
  width="800" height="450" fetchpriority="high" decoding="async"
  alt="Product hero"
/>
Lines: 6Reflows: CLS 0.00 (intrinsic aspect ratio)Dependencies: Preload Scanner + off-thread decode

Preload scanner fetches exact AVIF width immediately with high network priority.

Under the Hood

Raw compressed bytes (AVIF, WebP, JPEG) cannot be painted directly to screen; the engine must decompress them into an uncompressed RGBA bitmap in RAM (a 2000×1500 image expands to 12 MB) and upload it to GPU Compositor Layers.

  1. The Preload Scanner reads srcset, sizes, and devicePixelRatio before CSS finishes parsing, queuing only the best-fitting candidate.
  2. width and height HTML attributes compute an intrinsic aspect-ratio box during initial layout, preventing CLS.
  3. decoding="async" moves bitmap decompression onto a background thread so scrolling never drops a frame.
HTML
<picture>
  <source type="image/avif" srcset="/hero-800.avif 800w, /hero-1600.avif 1600w" sizes="100vw" />
  <img src="/hero-800.jpg" width="800" height="450" fetchpriority="high" decoding="sync" alt="Hero" />
</picture>

Problem Genealogy

  • 2014 (<picture> & srcset): Ended the era of shipping 4 MB desktop JPEGs to 320 px phones.
  • 2019 (width/height Aspect-Ratio Mapping): Browsers mapped HTML dimension attributes to CSS aspect-ratio, fixing responsive CLS.
  • 2022+ (fetchpriority & AVIF): Gave developers direct priority control over LCP images without abusing <link rel="preload">.

Production Pitfalls

Production Pitfall
  • loading="lazy" on the hero image: Lazy-loading above-the-fold images delays the LCP fetch until after layout and intersection checks complete, often adding 500+ ms to LCP.
  • CSS background-image for LCP heroes: Background images stay invisible to the preload scanner until CSS downloads and matches a DOM selector.
When Not to Use
  • When not to use decoding="async": On the primary above-the-fold LCP image, decoding="sync" (or omitting async) avoids a brief blank frame while the rest of the page paints.

Connections & Logical Next Steps

Network & PerformanceResponsive Images & Decoding