
On this page
I moved my portfolio from a React + Vite app to Next.js 16 with Server Components, image optimization and Cache Components. I expected a great Lighthouse score out of the box. On mobile it was 74–87, and the Largest Contentful Paint (LCP) was over 4 seconds on every page.
This post covers what was actually slow, how I found it, and the fixes that took the pages to 91–99. Every number below is the median of several Lighthouse mobile runs against a production build (next build + next start).
The results
- Mobile LCP (home page)
- 4.4s → 0.9s
- Lighthouse score (projects page)
- 79 → 99
- Layout shift (CLS) on every page
- 0
| Page | Before | After | LCP after |
|---|---|---|---|
| Home | 81 | 96 | 0.93s |
| About | 83 | 91 | 3.33s |
| Services | 84 | 99 | 0.91s |
| Projects | 79 | 99 | 0.93s |
| Contact | 87 | 99 | 0.91s |
The About page is the outlier: its LCP element is a large profile photo, so it is limited by the image download, not by JavaScript.
Problem 1: a fade-in animation was delaying LCP by 3 seconds
Every page was wrapped in a page transition that started at opacity: 0 and faded in. The hero text did the same. It looked smooth, but Chrome does not count an element with opacity 0 as painted. The largest text block was in the HTML immediately, yet LCP was only recorded after the JavaScript loaded, hydrated and finished the animation.
The fix was to keep the entrance animations but drop the opacity part. Slide and zoom only change transform, so the content counts as painted from the first frame:
// Before: invisible until the animation runs
<div className="animate-in fade-in slide-in-from-bottom-5 duration-300">
// After: visible from the first paint, still animated
<div className="animate-in slide-in-from-bottom-5 duration-300 motion-reduce:animate-none">Problem 2: infinite framer-motion loops kept the main thread busy
The home page had floating shapes, rotating icons, a shimmer on every button and animated SVG circles, all built with framer-motion and repeat: Infinity. Each one runs JavaScript on every frame. On a throttled mobile CPU that showed up as Total Blocking Time (408ms on the projects page).
I replaced every endless loop with a CSS @keyframes animation. The browser runs these on the compositor, so they cost no JavaScript at all, and several components no longer needed to be Client Components:
@theme inline {
--animate-float-a: float-a 4s ease-in-out infinite;
--animate-spin-slow: spin-slow 20s linear infinite;
@keyframes float-a {
0%, 100% { transform: translateY(0) rotate(0deg); }
50% { transform: translateY(-20px) rotate(5deg); }
}
}Problem 3: 14 project cards measuring the DOM during hydration
Each project card used framer-motion's layout and whileHover. With 14 cards, that is 14 components measuring layout while the page hydrates, right when the first card image should be painting. A plain CSS hover does the same job:
<div className="transition-transform duration-200 hover:scale-[1.02]
motion-reduce:transition-none
[content-visibility:auto] [contain-intrinsic-size:auto_560px]">content-visibility: auto also lets the browser skip layout and paint for cards that are still off-screen. The contain-intrinsic-size value is a placeholder height so the scrollbar doesn't jump.
Problem 4: full-page screenshots used as card thumbnails
The cards showed a 16:9 crop of full-page screenshots that were several thousand pixels tall. next/image resized them, but it still had to encode a tall image. I pre-cropped each one to a 1280×720 WebP thumbnail with the same centre framing. One card image dropped from 94.6 KB to 13.8 KB at the size the grid actually requests. The full screenshots are still used, but only inside the project details modal.
Problem 5: JavaScript that wasn't needed for the first paint
- The project details modal (carousel, swipe, keyboard navigation) now loads with
next/dynamiconly when it opens. Its code is preloaded on hover, focus or touch, so it still opens instantly. - The EmailJS SDK is imported inside the contact form's submit handler (
await import("@emailjs/browser")), not at the top of the file. - A barrel file undid the lazy loading. The folder's
index.tsre-exported the modal, which put it back into every page's initial JavaScript. Lazy components must not be re-exported from a barrel.
Problem 6: the LCP image wasn't prioritised
On the projects page the LCP element is the first card's image. I gave exactly that one image preload, which adds a <link rel="preload"> in the <head>, so the browser starts the download before React runs. Every other card image stays lazy.
How to measure without fooling yourself
- Test a production build (
next build+next start).next devis slow on purpose and always scores badly. - Run Lighthouse 3–5 times per page and use the median. A single run can be off by 10 points.
- Ignore the first run after starting the server: images are optimized on the fly the first time they are requested.
- Check
benchmarkIndexin the Lighthouse JSON. On my laptop it dropped from ~1750 to ~600–1300 when Chrome and VS Code were busy, and an unchanged page fell from 99 to 87. - If Lighthouse says
NO_FCP, keep the browser window in the foreground and dock DevTools to the page.
Checklist
- No
opacity: 0/ fade-in on anything above the fold, including page transitions. - No
repeat: Infinityin framer-motion: use CSS keyframes. - No layout animations on long lists; use CSS hover and
content-visibility: auto. - Pre-cropped thumbnails for cards, never full-page screenshots.
- Modals and SDKs loaded on demand; never re-exported from a barrel.
- Exactly one
preloadimage per page: the LCP image.
Frequently asked questions
Why is my Next.js LCP slow even though the HTML is server-rendered?
Check whether the LCP element or one of its parents starts at opacity: 0 (a fade-in or page transition). Chrome only records LCP once the element is visible, so the animation's JavaScript decides your LCP.
Does framer-motion hurt Lighthouse scores?
One-off animations are fine, especially with LazyMotion. Infinite loops and layout animations on many elements run JavaScript on the main thread and raise Total Blocking Time. Use CSS keyframes for loops.
Why does my Lighthouse score change every time I run it?
Lighthouse simulates a slow phone on your own CPU, so other apps affect the result. Use a production build, take the median of several runs, and compare the benchmarkIndex between runs.
- Next.js
- Performance
- Lighthouse
- Core Web Vitals
Keep reading
FoodHub · Restaurant ordering & delivery · Australia
FoodHub: Building a White-Label Restaurant Ordering SaaS
A white-label SaaS for an Australian founder that lets any restaurant launch its own commission-free ordering and delivery website, with live rider tracking and Stripe Connect payouts. Built solo, end to end.
- Live on the platform
- 2 restaurants
- Storefront, admin console, API
- 3 apps

React & Next.js7 min read
Next.js 16 Cache Components: What Broke When I Turned It On (and the Fixes)
I enabled Cache Components on this site, a Next.js 16 portfolio with a blog and case studies. Here is every error and surprise I hit, why it happens, and the exact code that fixed it.
