
Lazy-Loading Your Hero Image Makes LCP Worse
- كاتب موثّق
محتويات المقال
loading="lazy" to every <img> through a shared image component. Image bytes drop, and the landing page's LCP gets worse. We rebuilt the page and loaded it in headless Chromium 156 on a 412px-wide viewport, with the network emulated at 150 ms latency and 1.6 Mbps through the DevTools protocol, and a stylesheet from a server that takes 600 ms to answer. Over five runs, the median LCP was 1.77 s with an eager hero and 2.42 s with a lazy one. The eager hero was requested at 0.19 s; the lazy one only at 1.13 s, right after the stylesheet finished.
The common misconception
What actually happens
Lazy means "wait for a condition"
loading attribute as deferring the fetch until some conditions are met, and eager, the default, as fetching immediately. In practice the condition is distance from the viewport: Chrome starts a lazy image once it's within 1,250px on fast connections or 2,500px on slower ones, so images arrive just before the user scrolls to them.
The browser can't measure distance before layout
Where the delay lands in LCP
Lazy loading still earns its place below the fold
loading="lazy" removed from four product images far down the page, they downloaded alongside the hero and LCP rose to 3.97 s, on a local HTTP/1.1 server.
fetchpriority is a hint for when images compete
fetchpriority="high" as signaling a high-priority fetch relative to other resources of the same type. web.dev calls it a hint, not a directive, and reports LCP in a Google Flights test improving from 2.6 s to 1.9 s. On our page, with only one image competing, it made no measurable difference: it pays off when several images compete. Keep it to one or two images; web.dev notes that hinting more makes it unhelpful.
<!-- Every image lazy, the hero included --><img src="/hero.jpg" alt="Summer sale: 30% off running shoes" width="1600" height="900" loading="lazy"><img src="/p1.jpg" alt="Trail runner" width="800" height="600" loading="lazy"><!-- Hero: eager (the default), discoverable and hinted --><img src="/hero.jpg" alt="Summer sale: 30% off running shoes" width="1600" height="900" fetchpriority="high"><!-- Below the fold: lazy --><img src="/p1.jpg" alt="Trail runner" width="800" height="600" loading="lazy">PerformanceObserver check. This one logged a warning in our run for the lazy version only:
new PerformanceObserver((list) => { const lcp = list.getEntries().at(-1); if (lcp.element?.getAttribute("loading") === "lazy") { console.warn("LCP image is lazy-loaded:", lcp.element); }}).observe({ type: "largest-contentful-paint", buffered: true });loading | fetchpriority | ||
|---|---|---|---|
high | |||
lazy | |||
How to apply it in your project
Find the LCP element per template Run the observer above, or check the LCP element in the DevTools Performance panel, on mobile and desktop widths. The fold moves with the viewport, so the LCP image can differ between them. Make the hero eager and discoverable Remove loading="lazy"from it, keep its URL in a plainsrcorsrcsetin the server's HTML, and addfetchpriority="high".Make lazy the default below the fold only Give your image component an explicit prop such as priorityfor above-the-fold images, instead of one global default for every image.Measure the result in the field Compare the 75th percentile LCP before and after the change in your real-user data, not only in one lab run.
Key takeaways
loading="lazy"defers the fetch until layout shows the image is near the viewport, so it waits for CSS and layout.Eager images are found by the preload scanner and requested while the HTML is still arriving. Never lazy-load the LCP image: web.dev calls it unnecessary resource load delay. Lazy-load images below the fold, where it saves bytes and reduces competition with the hero. Use fetchpriority="high"on the hero, and keep the hint to one or two images.
التعليقات (0)