← Back to Frontend, page 1

frontend-0001 · Medium mid

A product page has a mobile LCP of 4.8 seconds in field data. How do you find the cause and fix it?

Find the LCP element first, then split the 4.8 seconds into four parts: server response, time before the resource starts loading, resource download, and time before the element renders. Fix the largest part. For a late hero image this usually means putting the image in the HTML, raising its priority, and not lazy loading it.

Full answer

Start from field data, because the lab can hide the problem. Check which element is the LCP element on real mobile visits, then reproduce on a throttled mobile profile.

LCP is the time until the largest image or text block in the viewport is painted. It has four parts that add up:

  1. Time to first byte (TTFB): how long the server and network take to return the HTML.
  2. Resource load delay: the gap between the HTML arriving and the browser starting to fetch the LCP image.
  3. Resource load duration: the download time of the image itself.
  4. Element render delay: the gap between the image arriving and it being painted, often caused by blocking CSS or JavaScript.

Measure all four, and attack the biggest one.

  • A large load delay usually means the image is not in the initial HTML. It is set by JavaScript, written as a CSS background, or marked loading="lazy". Put an <img> with src in the markup and add fetchpriority="high".
  • A large load duration means the file is too big. Resize it, use srcset and sizes, and use a modern format such as WebP or AVIF.
  • A large TTFB means the page is slow on the server or has no CDN cache. Cache the HTML at the edge, or reduce server work.
  • A large render delay means something blocks rendering. Look for big CSS files, synchronous scripts in the head, and client rendering that waits for an API call before it creates the image.

The code below reads the LCP element in the browser with the standard PerformanceObserver. The fixed page has a visible <img> with dimensions, high priority and no lazy loading.

After each change, run the same throttled test and compare the four parts. If the numbers do not move, the change was not on the critical path.

html
<img id="hero" src="/img/hero.jpg" width="800" height="400" fetchpriority="high" alt="Course hero">
<script>
  // Read the largest contentful paint candidates as the page loads.
  new PerformanceObserver((list) => {
    const last = list.getEntries().at(-1);
    window.lcp = { time: Math.round(last.startTime), tag: last.element && last.element.tagName, url: last.url };
  }).observe({ type: 'largest-contentful-paint', buffered: true });
</script>

Run in headless Chrome 156 through Playwright. Two full runs gave the same results. The image is a 1 pixel placeholder served by a local test server, so the measured time is not meaningful. The check confirms that the observer reports the image as the LCP element. Throttling, field data and the server steps were not run.

Key points

  • Find the LCP element before changing anything.
  • Split LCP into TTFB, load delay, load duration and render delay.
  • A hero image should be in the HTML, with fetchpriority high, and never lazy loaded.
  • Field data decides whether the fix worked, not one lab run.

Common mistakes

  • Optimizing every image on the page when only one element is the LCP element.
  • Adding loading="lazy" to the hero image, which delays the request.
  • Trusting a single Lighthouse score on a fast laptop instead of mobile field data.
  • Compressing the image when the real delay is a client-side API call before the image tag exists.

Follow-ups

  • How would the answer change if the LCP element were a heading and not an image?
  • What does fetchpriority="high" change, and what does it not change?
  • How do you confirm in production that the fix worked?

Tips

  • Name the four LCP parts out loud before proposing any fix.
  • Say which tool gives which data: CrUX or RUM for field, Lighthouse or DevTools for lab.