Improve LCP: remove what competes with your hero image

Improve LCP by clearing the hero image's path: a 177 KB analytics preload, a 117 KB phone logo, an unusable preconnect and an image proxy that did nothing.

By

On the first load of a page, everything competes for the same bandwidth. Most advice on how to improve LCP starts with the image itself: compress it, resize it, serve a newer format. Those all help, and they leave a second question open: what is the main photo sharing the connection with? On a photo marketplace I work on, that was the question to answer. This post goes through what I removed from the photo's path, from an analytics script to a proxy that did no work, and how to look for the same on your own pages. One limit up front: these commits came with no before and after LCP figure, so I can tell you what changed and why, but not by how much.

Why the hero image loses the race

Largest Contentful Paint measures when the biggest element in the viewport renders, and on a photo site that is usually a photo. A good score is 2.5 seconds or less at the 75th percentile of page loads.

You can shrink that photo as far as quality allows and still lose time, because the file doesn't download alone. The web.dev guide to optimizing LCP calls this network contention: a resource can take a long time to load if many others are loading with it. It also warns that high fetch priority stops helping when you hand it to lots of resources at once.

So I treat the first load as a budget. Anything that isn't the main photo, the HTML or the CSS needs a reason to be on the wire at that moment.

How do you improve LCP when the image is already small?

Look at what else downloads during the same seconds, and remove or delay it. Open the network waterfall on a throttled connection and list every request that starts before the LCP image finishes. Scripts, preloads and oversized small assets are the usual finds. Then give the LCP image high fetch priority, so it wins the requests that remain.

The analytics script that loaded before the photo

The first competitor was gtag.js. It was preloaded in the head, so its 177 KB raced the LCP image on every template. Nobody wrote that preload by hand. In the App Router, the afterInteractive strategy on next/script calls React's preload for the script, which puts a link in the head even though the script runs later.

The fix is one word:

<Script
  src={`https://www.googletagmanager.com/gtag/js?id=${GA_ID}`}
  strategy="lazyOnload"
/>

Next.js documents lazyOnload as loading during browser idle time, after the page's resources have been fetched. The small inline snippet that sets up dataLayer stays on afterInteractive, so hits made before gtag.js arrives wait in the queue and go out when it lands.

The trade-off is real: a visitor who leaves before the page finishes loading may never send a hit. My default on a page whose job is showing a photo is to accept that. If analytics numbers matter more than speed for a given site, that call could go the other way. Purchases shouldn't depend on it either way, which is why I record them server-side from the Stripe webhook.

Preloads that jumped ahead of the hero

A preload is a claim that this file matters more than whatever the browser would have fetched next. Make that claim for the wrong file and you are paying to slow down the right one.

The first content row on the homepage was marked as a priority image. That row sits below the hero, yet it was being preloaded ahead of it, so I removed the prop. The hero preload now gets high priority.

<Image src="/hero.webp" alt="" fill fetchPriority="high" sizes="100vw" />

Check this against your Next.js version. The Next.js Image docs say priority is deprecated from version 16 in favour of preload, and that in most cases you should use loading="eager" or fetchPriority="high" instead of preload. They also list fetchPriority as a case where preload doesn't belong. The site I changed runs Next.js 15, where priority is still the normal prop and sits next to fetchPriority="high". That snippet is what I would write on 16.

My rule is one image per template gets this treatment. If different images can be the LCP element depending on the viewport, the docs advise against preloading any of them.

Small files that weren't small

Logos and icons don't look like performance problems, so they escape review. Two of them here were the same 117 KB file doing a job it was far too big for.

  • Phone navbar logo. It displays at 40 pixels and was loading a 117 KB image. It is now 5 KB.
  • Manifest icon. The web manifest pointed at the same 117 KB logo. It now points at an 18 KB icon.
  • Homepage banners. These moved to WebP at about half the size.

That last group matters more after the change in the next section, since those local files now ship exactly as they sit in the repo. When you know what a file costs, sizing it by hand is cheap. I wrote about the upload side of this in image processing pipelines with Sharp and S3.

A preconnect that couldn't be reused

The image page opened an early connection to the image CDN, which is the right idea when your photos live on another domain. The tag carried crossOrigin:

<link rel="preconnect" href="https://images.example.com" crossorigin>

Browsers keep CORS and no-cors connections apart. The photo is a plain no-cors fetch, so it could not reuse that warmed connection. The preconnect was spending effort on a connection that the photo wouldn't touch, so I dropped the attribute.

The attribute has to match how the resource is fetched. Fonts load in anonymous mode and need crossorigin. A normal <img> doesn't. Copying a font preconnect for an image domain is an easy way to end up here.

Removing an image optimizer that wasn't optimizing

This one was hiding in plain sight. Next's image optimizer depends on sharp, and sharp needs a newer CPU than the VPS has, so the optimizer couldn't run there. /_next/image still answered every request, but all it did was proxy each file through unchanged. Every photo took an extra hop and got nothing for it.

Worse, that hop stood between the browser and the image CDN, which can pick the format per browser. Setting images.unoptimized to true in the Next config sends browsers straight to the source URL, and Cloudflare Images can then hand them AVIF. The docs describe unoptimized as serving the source image as-is, with no change to quality, size or format, so it only makes sense when something else is doing that work or the files are already right.

If you self-host Next.js, it's worth requesting one /_next/image URL with an Accept header for AVIF and comparing the size and type of the response with the original file. A proxy that returns the same bytes looks exactly like a working optimizer until you check.

The short version

To improve LCP, stop asking only how small the hero is and start asking what it shares the connection with. On this site that meant moving a 177 KB analytics script out of the first load, taking a preload off a below-the-fold row, cutting a 117 KB logo to 5 KB, fixing a preconnect the photo couldn't reuse and skipping an optimizer that only proxied files. I have no before and after figure from these commits, so measure your own: record LCP in the field, change one competitor at a time, and watch the waterfall on a slow connection. Looking at what the server really sends is also how you catch Next.js metadata reaching Googlebot in the body.

If you'd like a second pair of eyes on a slow Next.js site, see my services page.

Want this kind of work on your product?

Get in touch