LCP Image Optimization
LCP image optimization focuses on getting the image that becomes the Largest Contentful Paint element discovered early, prioritized appropriately, transferred efficiently, and rendered without unnecessary delay. The goal is to reduce the time until the main above-the-fold visual is actually painted.
Largest Contentful Paint (LCP) measures when the largest relevant image, text block, or other content element in the viewport becomes visible. When an image is the LCP element, its loading path can dominate the page's LCP time, so optimizing that image is often more effective than optimizing smaller images that do not affect the metric.
Start with discovery. The browser needs to find the image resource before it can fetch it. An LCP image referenced directly by an HTML `<img>` is generally discoverable earlier than an image whose URL is only revealed after JavaScript executes or after CSS processing. Avoid unnecessarily hiding the LCP image behind client-side work, and consider preloading it when early discovery cannot otherwise be achieved.
Next, control priority and transfer cost. The LCP image should not be lazy-loaded when it is immediately visible; `loading="lazy"` can delay a resource that is needed for the initial viewport. Appropriate fetch priority, such as `fetchpriority="high"` where supported, can communicate that the resource is important. The image itself should also be correctly sized and encoded so the browser does not download substantially more data than the rendered dimensions require.
Finally, consider rendering and delivery. Use responsive image mechanisms such as `srcset` and `sizes` so the browser can select an appropriate resource, and serve modern formats when they provide a useful size reduction without unacceptable quality loss. CDN delivery, caching, compression, and correct image dimensions can reduce network and layout delays. Measure the result with real-user data and lab tooling rather than assuming that a change improved LCP.
Key points
- Make the LCP image discoverable as early as practical.
- Do not lazy-load an image that is immediately visible and likely to be the LCP element.
- Use appropriate priority signals such as `fetchpriority="high"` when justified.
- Serve an appropriately sized, efficiently encoded image using responsive image techniques.
- Measure LCP after changes; improving an image that is not the actual LCP element may have little effect.
Interview questions
What makes an image a good target for LCP optimization?
The target is the image that actually becomes the Largest Contentful Paint element, usually a prominent above-the-fold visual. I would first verify that with browser performance tooling or field data. Then I would examine when the image is discovered, when its request starts, how many bytes it transfers, and when it is painted. Optimizing unrelated images may reduce overall bandwidth without materially improving LCP.
Why can lazy loading hurt LCP?
Lazy loading tells the browser that an image can wait until it is near the viewport. That behavior is useful for below-the-fold images, but it can be counterproductive for an image that is immediately visible and needed for LCP. The browser may postpone the request or otherwise delay its loading path. For a visible LCP image, I would normally avoid `loading="lazy"` and verify the resulting request timing.
How do `srcset` and `sizes` help an LCP image?
They allow the browser to choose an image resource that better matches the rendered size and device conditions. Without responsive candidates, a page can download a much larger image than the viewport needs. `srcset` supplies candidate resources, while `sizes` describes the expected rendered width under different layout conditions. This can reduce transfer time while preserving appropriate visual quality.
When would you use preload for an LCP image?
Preload can help when the LCP resource is otherwise discovered late, such as when its URL is hidden behind a rendering or resource-discovery dependency. It should not be added automatically to every large image because preloads consume network and connection resources. I would first determine whether normal HTML discovery is already early enough, then use preload when there is a demonstrated discovery bottleneck. Afterward, I would measure whether the earlier fetch improves LCP without harming other critical resources.
If the LCP image request starts immediately but LCP is still slow, what would you investigate?
I would separate network transfer time from the remaining delay. The image might be too large, poorly encoded, slow to download from the origin or CDN, or blocked by connection and server latency. I would also inspect whether the main thread is busy, whether rendering is delayed, and whether CSS or other dependencies prevent the image from being painted promptly. The goal is to identify the dominant segment of the LCP timeline rather than applying another generic image optimization.