Image & Media Optimization — Cheat Sheet

FE Lead prep · ref 06

The frame & the four disciplines

Images = LCP element on ~85% desktop / ~76% mobile pages + the heaviest bytes. On a hotel site, images ARE the page.
1. Right format (AVIF→WebP→JPEG) · 2. Right size (srcset/sizes) · 3. Right loading (lazy below / prioritize LCP) · 4. Reserve space (width/height).

Format — AVIF/WebP

<picture>
 <source type="image/avif" srcset="h.avif">
 <source type="image/webp" srcset="h.webp">
 <img src="h.jpg" width=800 height=600 alt>
</picture>

Size — srcset / sizes

<img srcset="h-400 400w, h-800 800w,
  h-1600 1600w"
 sizes="(max-width:600px) 100vw, 33vw"
 width=800 height=600 alt>

Loading — opposite moves for two images

ImageDoWhy
Below foldloading="lazy" + decoding="async"save bytes, free network
LCP (hero/1st)fetchpriority="high", never lazy (opt. preload)it's the metric — Google test cut LCP 2.6→1.9s

Network-aware (adaptive) loading

CLS — reserve the box

At scale (the Lead move)

Lead one-liners (memorize)

Frame  “On a hotel site the images are the page — LCP element and heaviest bytes. Image strategy is the main perf lever, not a detail.”
Loading  “Lazy below the fold, but the LCP image gets fetchpriority=high and is never lazy — a blanket lazy rule catching the hero is the most common own-goal.”
CLS  “Every image ships with width/height so the box is reserved before the bytes land — that's most of CLS gone.”
Scale  “At our scale it's a pipeline: an image CDN deriving format/size per request + an <Image> component + a CI image budget — not hand-authored <picture>.”
Adaptive  “For data-sensitive markets I serve lighter images to Save-Data users at the CDN — explicit intent, works everywhere. navigator.connection is Chromium-only and a guess, so it's enhancement, never a gate; and I Vary: Save-Data.”

Sources: MDN — fix image LCP · web.dev — fetchpriority · web.dev — responsive images · web.dev — image CDNs · HTTP Archive — Media

Don't fail the interview

1. Images = LCP element ~80% of pages + heaviest bytes → the #1 lever on a photo site.
2. NEVER lazy-load the LCP image. Blanket lazy rule catching the hero = LCP own-goal. Eager+fetchpriority=high above, lazy below.
3. Wrong sizes wastes everything — must match real rendered width or browser picks too-big a file.
4. srcset = resolution switching (same image); different crop needs <picture media> (art direction). Don't reach for <picture> when a plain <img srcset> suffices — only for format or crop.
5. Always width/height — dimensionless images shoving content = #1 image CLS.
6. Don't AVIF-everything — SVG icons, PNG lossless transparency; match format to content.
7. At scale = pipeline, not per-PR nagging: CDN + <Image> component + CI budget.
8. Network-aware = lead with Save-Data header at CDN (explicit, works everywhere; Vary: Save-Data). navigator.connection is Chromium-only + a guess → enhancement, never the gate.