Lesson 7 of 30
Images are almost always the biggest bytes on a page, and "optimize the images" is really three separate decisions layered together: which format, what size for which device, and when to actually load it.
13 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 3
A developer runs a script that adds `loading="lazy"` to every `<img>` tag on the site, including the homepage's hero image, which is also the page's LCP element. What's the likely effect on LCP?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
A real image strategy is three layered decisions, not one setting:
<picture> lets you offer a modern format with an older-format fallback, and srcset can do the same job for a plain <img>.srcset plus sizes lets the browser pick from several resolutions of the same image, so a phone downloads a phone-sized file instead of the same 2400px-wide image a desktop hero uses.loading="lazy" defers a below-the-fold image's fetch so it doesn't compete with above-the-fold resources for bandwidth early in the page load.Each decision is independent: you can pick the wrong format on a correctly-sized, correctly-prioritized image, or the right format on an image that's still loading at the wrong priority.
<picture>
<source
type="image/avif"
srcset="/hero-480.avif 480w, /hero-1200.avif 1200w, /hero-2400.avif 2400w"
/>
<source
type="image/webp"
srcset="/hero-480.webp 480w, /hero-1200.webp 1200w, /hero-2400.webp 2400w"
/>
<img
src="/hero-1200.jpg"
srcset="/hero-480.jpg 480w, /hero-1200.jpg 1200w, /hero-2400.jpg 2400w"
sizes="100vw"
width="2400"
height="1350"
alt="Product dashboard overview"
/>
</picture>
The browser walks the <source> elements in order, picks the first format it supports, then within that format picks the resolution that matches the actual viewport via sizes. The plain <img> at the bottom is the fallback for browsers that support neither modern format, and it still carries its own srcset for sizing. width/height are present regardless of any of this — they reserve layout space immediately, which is the same fix the Core Web Vitals lesson covers for CLS, and it doesn't go away just because you've solved format and sizing.
loading="lazy" on the LCP image is a self-inflicted LCP regression, not a neutral choice. Lazy-loading is for below-the-fold images specifically; the above-the-fold hero or LCP candidate should load eagerly, at high priority.sizes without a correct srcset (or vice versa) silently defeats responsive sizing. The browser needs both: srcset for the candidate resolutions, sizes for how much viewport space the image will actually occupy, so it can pick correctly.width/height (or CSS aspect-ratio) is still required even with modern formats and lazy loading. None of format, sizing, or loading strategy reserves layout space on their own — that's a separate, still-necessary fix for CLS."The homepage hero image is huge and it's hurting LCP — walk me through how you'd fix it" is a real, layered question, and treating it as three separate levers (format, responsive sizing, loading priority) rather than one vague "compress the image" answer is what distinguishes a senior response.