Skip to the page

Loading fast: critical path, hints, images, fonts, caching · core

Images: formats, srcset and sizes, lazy loading, dimensions

Serve each user the smallest good-enough image: modern formats (AVIF, WebP), responsive sizes with srcset and sizes, explicit dimensions to avoid CLS, lazy loading only below the fold, and high priority for the LCP image.

The notes

What you must know

  • Formats: AVIF is usually smallest, then WebP, then JPEG. Use <picture> with <source type> for fallbacks, or an image CDN that picks the format from the Accept header.
  • srcset with w descriptors lists files and their real widths; sizes tells the browser how wide the image will be in CSS pixels for each layout. The browser picks a file using slot width x device pixel ratio.
  • x descriptors (1x, 2x) are for fixed-size images like logos. <picture> with media is for art direction (a different crop on mobile).
  • Always set width and height attributes (or CSS aspect-ratio). The browser reserves space before the image loads, which prevents CLS.
  • loading="lazy" for below-the-fold images only. The LCP/hero image must load eagerly with fetchpriority="high". decoding="async" lets the browser decode off the critical path.
  • Images in CSS backgrounds are discovered late (after CSS). Prefer <img> for important images.
  • Serve images from a CDN with long cache lifetimes and content-hashed URLs; resize on the server, never ship a 2400 px image to a 360 px phone.

The red pen

Common traps: mistake → fix

  • Mistake: "srcset without sizes is fine"

    Fix: without sizes the browser assumes 100vw and often downloads a larger file than needed.

  • Mistake: "Lazy-load everything"

    Fix: lazy-loading the hero delays LCP.

  • Mistake: "CSS can scale one big image down"

    Fix: the user still downloads and decodes the big file.

Easy to hard

Questions interviewers ask, easy to hard

  1. How do you serve images for a product grid on 2G phones and retina laptops?
  2. Explain srcset with w descriptors and the sizes attribute.
  3. How do placeholders (blur, dominant colour) avoid CLS?
  4. What does next/image do for you, and what does it not do?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview