Core Web Vitals on Next.js landing page: how to find and fix LCP and CLS
What numbers matter
Google ranks the page based on field data from real Chrome users (CrUX report), 75th percentile over the last 28 days. “Good” thresholds: LCP no more than 2.5 seconds, CLS no more than 0.1, INP no more than 200 milliseconds. Goals like “LCP less than 1.2 seconds” can be set as an internal guideline, but for searching there is no difference between 1.2 and 2.4 seconds: both fall into the “good” range.
Lighthouse in DevTools is a laboratory measurement on your machine with network emulation. It is useful for debugging, but may diverge from field data in both directions. Make decisions based on PageSpeed Insights (section with user data) or your own telemetry.
Step 1. Collect field data with attribution
The web-vitals library in the attribution assembly reports not only the value, but also the element that called it:
// app/web-vitals.tsx
"use client";
import { useEffect } from "react";
export function WebVitals() {
useEffect(() => {
import("web-vitals/attribution").then(({ onLCP, onCLS, onINP }) => {
const send = (metric: { name: string; value: number; rating: string; attribution: unknown }) => {
navigator.sendBeacon("/api/vitals", JSON.stringify({
name: metric.name,
value: metric.value,
rating: metric.rating,
path: location.pathname,
attribution: metric.attribution,
}));
};
onLCP(send);
onCLS(send);
onINP(send);
});
}, []);
return null;
}For LCP, the attribution contains an element selector and a breakdown of time into stages: waiting for a server response, delay in starting resource loading, loading itself, rendering delay. This immediately shows you where to look. For the CLS, the element that has moved the most.
Step 2. LCP: find what exactly is stopping you
Long delay before the image starts loading. The browser learns about the LCP image late: it is inserted via CSS background-image, rendered by the client component after hydration, or labeled loading="lazy". The solution is the usual <img> in server markup with high priority:
import Image from "next/image";
import hero from "@/public/hero.webp";
export function Hero() {
return (
<Image
src={hero}
alt="Экран аналитики заказов"
priority // Next.js 15: preload + fetchpriority="high", без lazy
sizes="(max-width: 768px) 100vw, 1200px"
placeholder="blur"
/>
);
}priority is placed on only one image - what is actually the LCP on the first screen. If you tag five pictures to them, they will start competing for the channel.
Long server response. If a large portion of attribution is due to waiting for the first byte, the problem is not in the frontend. Check whether the page has become dynamic due to a call to cookies() or headers() in layout, and whether it can be served statically or with revalidation.
LCP is text, not a picture. Then the time comes down to the font. Use next/font: the font is downloaded from your domain, and a fallback system font is adjusted based on metrics.
import { Inter } from "next/font/google";
export const inter = Inter({ subsets: ["latin", "cyrillic"], display: "swap" });Step 3. CLS: reserve a seat
Shifts on landing pages almost always produce four sources.
Images and videos without dimensions. next/image with static import puts width and height itself. For external images, set dimensions or aspect-ratio.
Ad units. An AdSense or YAN slot gets height only after the ad is loaded. Reserve the minimum height for a typical format:
.ad-slot { min-height: 280px; }
@media (max-width: 640px) { .ad-slot { min-height: 250px; } }If the ad does not load, there will be empty space - this is a lesser evil than shifting all the content. Do not insert advertisements above text that has already been drawn.
Cookie banners and notifications. Show them on top of the content (position: fixed), rather than inserting them into the stream above the header.
Fonts. Without size-adjust in the fallback font, the text is rearranged when the primary font is loaded. next/font solves this automatically; for self-connected fonts, set size-adjust and ascent-override to @font-face for the fallback.
You can find shifts manually directly in the console:
new PerformanceObserver((list) => {
for (const entry of list.getEntries()) {
if (!entry.hadRecentInput) {
console.log(entry.value.toFixed(4), entry.sources?.map(s => s.node));
}
}
}).observe({ type: "layout-shift", buffered: true });Common errors
- Optimize using Lighthouse on a powerful laptop and be amazed by the CrUX report. Test with CPU throttling and on a real average phone.
- Put
loading="lazy"on everything, including hero. - Connect chat and analytics widgets synchronously in
<head>. Usenext/scriptwith theafterInteractiveorlazyOnloadstrategy. - Wait for changes in Search Console every other day. Field data are averaged over 28 days.
When you shouldn't chase numbers
If all three metrics are already in the green zone at the 75th percentile, further optimization will not provide an advantage in search. Time is better spent on content and INP on interactive pages. And don’t remove ads or functionality that makes money for the sake of metrics: reserved space solves the CLS problem without loss.