← All articles
PerformanceSeptember 20, 2024

Achieving 100/100 Lighthouse Scores in Next.js

Performance optimization strategies for modern web applications, from image optimization to code splitting.

By Kibet Brian

A perfect Lighthouse score is not vanity, it is a proxy for how the site feels on a mid-range phone with a mediocre connection. Most of the wins come from shipping less.

Fix images first

Images are usually the largest payload on the page. Serve modern formats at the right size, lazy-load below the fold, and give every image dimensions so the layout never shifts.

hero.tsx
<Image
src="/hero.webp"
alt="Dashboard"
width={1200}
height={630}
priority
sizes="(max-width: 768px) 100vw, 1200px"
/>

Split code by route and interaction

Heavy components that only appear on interaction should not be in the initial bundle. Dynamic imports with ssr disabled for client-only widgets cut first-load JavaScript dramatically.

Mind fonts and third parties

  • •Self-host fonts with display swap and subset to the glyphs you need.
  • •Defer analytics and chat widgets until after first paint.
  • •Audit every third-party script yearly, they accumulate silently.

Set a performance budget

Scores drift without a number to defend. Cap total JavaScript, image weight, and third-party requests, and enforce the budget in CI so a heavy pull request fails before it ships instead of after users feel it.

budget.json
[
{
"resourceType": "script",
"budget": 170
},
{
"resourceType": "image",
"budget": 250
},
{
"resourceType": "third-party",
"budget": 200
}
]

Measure on real devices

  • •Test on a mid-range Android phone, not just a flagship and a laptop.
  • •Throttle to 4G speeds, since office wifi flatters every site.
  • •Watch field data next to lab scores, users live in the field.

A perfect score held for a year beats a perfect score held for a week. Budgets, real devices, and regular audits are what keep the green numbers green.

Share this article