Responsive Images & Decoding
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.
Hero LCP Image: Naive <img> vs Prioritized Responsive <img>
Compare a lazy-loaded un-sized <img> against a fetchpriority=high, intrinsic-sized responsive image.
<img
src="/hero-2400w.jpg"
loading="lazy"
alt="Product hero"
/>Lazy loading stalls LCP discovery; missing width/height shifts content on load.
<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"
/>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.
- The Preload Scanner reads
srcset,sizes, anddevicePixelRatiobefore CSS finishes parsing, queuing only the best-fitting candidate. widthandheightHTML attributes compute an intrinsicaspect-ratiobox during initial layout, preventing CLS.decoding="async"moves bitmap decompression onto a background thread so scrolling never drops a frame.
<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/heightAspect-Ratio Mapping): Browsers mapped HTML dimension attributes to CSSaspect-ratio, fixing responsive CLS. - 2022+ (
fetchpriority& AVIF): Gave developers direct priority control over LCP images without abusing<link rel="preload">.
Production Pitfalls
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-imagefor LCP heroes: Background images stay invisible to the preload scanner until CSS downloads and matches a DOM selector.
- When not to use
decoding="async": On the primary above-the-fold LCP image,decoding="sync"(or omittingasync) avoids a brief blank frame while the rest of the page paints.
Connections & Logical Next Steps
The HTML preload scanner evaluates srcset, sizes, and fetchpriority before CSS layout runs.
Decoded image bitmaps are uploaded as GPU textures during compositing.
Hero image prioritization and aspect-ratio reservation govern LCP and CLS.