Next.js performance optimization starts with three checks: the page should render on the server, the Largest Contentful Paint (LCP) image should be preloaded, and client JavaScript should stay off the first load. A good mobile LCP is 2.5 seconds or less. Total Blocking Time (TBT) should be 200 ms or less. Cumulative Layout Shift (CLS) should be 0.1 or less.
The App Router already knows how to do each of those. A slow Next.js app is usually a page that opted out: "use client" on the route, a plain img for the hero, a Google Fonts stylesheet, or a chat widget in the document head. This guide maps those mistakes to the Lighthouse rows that move the score, with the Next.js 16 APIs that fix them.
The Next.js platform page is the short audit. This is the code. Metric-only loops live in how to fix LCP with AI, how to fix TBT with AI, and how to fix CLS with AI.
Read the score plan before you rewrite the app
Run the production URL on PageSpeed Exporter, mobile first. Download the stripped AIReport. It is the Lighthouse result with screenshots and passing audits removed, small enough to hand to Cursor, Claude, or ChatGPT.
Follow scorePlan, not savings.ms:
largest-contentful-paint— weight 25. MobiletargetFor90is 2500 ms. Desktop is 1200 ms.total-blocking-time— weight 30, the largest slice. MobiletargetFor90is 200 ms. Desktop is 150 ms.cumulative-layout-shift— weight 25.targetFor90is 0.1.pointsAtRiskis weight times one minus the metric score. Fix the largest number first.fieldDatais real Chrome users. It does not move on the next lab run. Search Console follows weeks later.
issues whose affectsMetrics includes the metric you picked are the rows to open. largest-contentful-paint-element names the node. bootup-time names the scripts. layout-shifts names the nodes that moved. stackPacks adds a Next.js hint when Lighthouse recognizes the app. passedAuditIds are already fine.
Desktop and a both-strategy run are on Starter and Pro. A free account includes 5 mobile reports a month, shared with the site and the MCP server. A homepage scan and one verification scan are two of those five.
A worked example
These numbers are one marketing homepage, not a survey. Before the three changes below, the mobile AIReport read:
- LCP 4.6 s, about 18 points at risk of 25. The element was a hero photo requested as a full-width file.
- TBT 740 ms, about 22 points at risk of 30. The route was a client component that imported a chart library.
- CLS 0.18. A font stylesheet arrived after first paint and reflowed the heading.
After the image, the server/client split, and next/font, a second mobile scan read LCP 2.1 s, TBT 160 ms, and CLS 0.04. The chart still loaded. It loaded after the score-critical work.
1. Preload one image, the LCP element
If largest-contentful-paint-element is an image, that file has to start in the document head. In Next.js 16, priority on next/image is deprecated. Use preload on that one image. Set sizes when the image is responsive or uses fill. Without sizes, a fill image is treated as 100vw and the browser downloads a larger file than the layout needs.
import Image from 'next/image'
export function Hero() {
return (
<Image
src="/hero.png"
alt="Product on a desk"
width={1200}
height={750}
preload
sizes="(max-width: 768px) 100vw, 720px"
/>
)
}
Use preload on a single above-the-fold image. A second preload competes with the real LCP file. Below-the-fold images stay on the default lazy load.
Give the image width and height, or a sized parent when you use fill. A missing box is a CLS bug even when the bytes are small. The image walkthrough that is not Next.js-specific is the LCP AI guide.
2. Keep the route on the server
TBT counts main-thread tasks after first paint. The usual Next.js cause is a route file that starts with "use client" and then imports a library the first view never runs.
Leave app/page.tsx as a Server Component. Split the heavy widget into its own client file and load it with next/dynamic. The import path has to be a literal, written at the top level of the module.
import dynamic from 'next/dynamic'
const Chart = dynamic(() => import('./chart'), {
loading: () => <div className="h-64" />,
})
export default function Page() {
return (
<main>
<Hero />
<Chart />
</main>
)
}
The reserved h-64 box is what keeps the chart from shifting the page when it arrives. ssr: false is for a widget that touches window during render. It is not a default. Turning off server rendering for the whole page puts LCP behind a JavaScript download.
On the next AIReport, bootup-time should no longer list that chart module at the top. If a third-party host is the long task, do not try to edit their file. Load it with next/script. afterInteractive is the default and still runs during hydration. A chat widget, heatmap, or social embed belongs on lazyOnload, which waits for idle time.
import Script from 'next/script'
export function Chat() {
return <Script src="https://example.com/chat.js" strategy="lazyOnload" />
}
beforeInteractive is for the rare script that must run before hydration. Analytics and support widgets are not that script. The longer main-thread loop is how to fix Total Blocking Time.
3. Self-host the font
A stylesheet link to a font host blocks text, then swaps the face and moves the heading. That shows up as render-blocking CSS and as CLS. next/font downloads the file at build time and applies a class that reserves the metrics.
import { Inter } from 'next/font/google'
const inter = Inter({
subsets: ['latin'],
display: 'swap',
})
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" className={inter.className}>
<body>{children}</body>
</html>
)
}
Call the font loader at module scope, once. A local file uses next/font/local with src pointed at the woff2. Delete the old font link from the layout so the browser does not download the face twice. Layout-shift detail belongs in how to fix CLS.
What to paste into the agent
Attach the AIReport and use a prompt that names the Next.js file, not a generic performance lecture.
You are optimizing a Next.js App Router app. The attached JSON is an AIReport.
Rules:
- Follow scorePlan. Fix the metric with the highest pointsAtRisk first.
- Ignore savings.ms until that metric's numericValue moves toward targetFor90.
- If the LCP element is an image, edit it to next/image with preload and sizes. priority is deprecated in Next.js 16.
- Do not add "use client" to a page that can stay a Server Component. Code-split heavy client widgets with next/dynamic and reserve their height.
- Load third-party widgets with next/script strategy="lazyOnload".
- Load fonts with next/font. Remove the old font stylesheet.
- Skip ids in passedAuditIds.
Then re-scan the same mobile URL. Stop when each lab metric in scorePlan is at or under targetFor90. Lab scores move about ±5 points between runs, so a 4-point wiggle is not a regression. fieldData staying red after a green lab run means the code fix worked and the 28-day Chrome window has not caught up.
Further Reading
- Next.js audits — run a URL and export the AIReport
- What is Largest Contentful Paint? — the 2.5 second field threshold
- What is Total Blocking Time? — the 50 ms long-task rule
- How to Fix Render-Blocking Resources — stylesheets and scripts in the head
- WordPress Core Web Vitals — the same metrics on a different stack
- Pricing — 5 free mobile reports, then Starter and Pro