Building PerformantFrontEnd: Every Performance Decision, Mistake and Fix
A performance blog has to be fast. Here is every decision I made building this site, the bugs that cost me seconds of LCP, how I found them and how I fixed them, with real numbers.

A blog about front-end performance has a simple rule: it has to be fast. Nobody takes advice on Largest Contentful Paint from a site that takes four seconds to show its own headline.
So when I built PerformantFrontEnd, I treated performance as a feature with a test suite, not a final polish. This article is the honest log of that work: the decisions I made up front, the bugs that slipped through anyway, how I found each one and how I fixed it. Every number here comes from measuring this site.
The rules I set before writing any code
Budgets are only useful if you set them before you have something to defend. These are the ones this site is held to, on every push, in CI:
| Check | Budget |
|---|---|
| Lighthouse (mobile) | Performance ≥ 95, Accessibility 100, Best Practices ≥ 95, SEO 100 |
| Largest Contentful Paint | ≤ 2.5 s |
| Cumulative Layout Shift | ≤ 0.1 |
| Total Blocking Time | ≤ 200 ms |
| JavaScript per page | ≤ 200 KB gzip in total, ≤ 30 KB of it specific to the page |
| Accessibility (axe) | Zero violations, light and dark mode, desktop to mobile |
The stack is Next.js 16 with the App Router, React 19, TypeScript and Tailwind CSS v4, deployed on Vercel.
1. Ship HTML, not JavaScript
The fastest JavaScript is the JavaScript you never send. Most of this site is articles, and articles don't need to run code in the browser to be read.
- Every content page is prerendered at build time. Next.js 16's Cache Components let each page be static HTML, with only the genuinely interactive pieces (search, filters, the newsletter form) hydrated on the client.
- Posts are compiled at build time. The articles are MDX files, compiled by Velite when the site builds, not when someone visits.
- Code highlighting happens at build time too. Shiki turns every code block into coloured HTML during the build. The highlighter, its grammars and its themes never reach the browser.
- Unknown posts get a real 404. At first, a mistyped article URL rendered the "not found" page with a 200 status, a soft 404 that search engines dislike. A small
proxy.tsnow checks the slug against the list of built posts and returns a genuine 404.
To keep myself honest, I wrote a small budget script that loads each page and adds up the gzipped JavaScript it fetches:
Shared by every route: 174.3 KB gzip
Budgets: total ≤ 200 KB, route-only ≤ 30 KB
route total route_only
/ 193.2 18.9
/blog 194.7 20.4
/blog/[post] 192.7 18.4
/about 185.4 11.1Most of the shared 174 KB is React and Next.js itself. The part I control, the code specific to each page, stays between 8 and 20 KB. I also checked the client bundles for anything that belongs only on the server: no Shiki, no MDX compiler, no Zod, no image library, no API key.
2. Images: the cheetah problem
The site's mascot is a cheetah, and it appears everywhere: the hero, article covers, cards, the newsletter. The first versions came straight from the design file, and on a high-density screen they were blurry.
The fix started with better source files: a set exported at three times the display size, trimmed to the artwork and saved as lossless WebP. next/image then serves each one as AVIF (smallest for flat cartoon art) with a WebP fallback, at the width the screen actually needs.
At least, that was the theory. Lighthouse disagreed:
The newsletter cheetah is 195 px wide. On a 2× screen that's 390 real pixels, and next/image had correctly told the browser so. The problem was the menu of widths the browser could choose from. Next.js's default list jumps from 384 straight to 640, so the browser, needing 390, had to take 640. The hero had the same problem: it needed 880 and got 1080, because the defaults skip from 828 to 1080.
The sizes attributes were right; the list of available widths was too coarse. The fix is one setting:
images: {
formats: ["image/avif", "image/webp"],
// The widths our layouts actually need at 1×, 2× and 3×.
imageSizes: [32, 48, 64, 96, 128, 160, 200, 256, 300, 340, 390, 440, 512],
deviceSizes: [640, 750, 828, 880, 960, 1080, 1200, 1440, 1920],
},I added the widths my layouts use and removed 2048 and 3840, since nothing on the site is shown wider than 720 px. That saved about 30 KB on the home page alone, and Next.js only generates a width the first time someone needs it, so a longer list costs nothing up front.
3. The 3.4-second headline
This was the biggest bug, and it hid in plain sight. Every page scored 100 on Lighthouse except the blog index:
The largest element on the page was its heading, "Every article, sorted by what's slow." Text should paint almost immediately, so why was it taking 3.4 seconds?
The blog index has search and topic filters that live in the URL (?topic=rendering&q=inp). To read the URL, the page used useSearchParams, which only works in client components, inside a Suspense boundary. And I had put the whole top of the page inside that boundary, heading included.
So the browser received HTML with the heading, painted it, and then, when React hydrated, the client component rendered the heading again. Chrome saw a new paint of the largest element and moved LCP to after the JavaScript had downloaded and run.
Simplified, the page looked like this:
<Suspense fallback={<BlogView posts={posts} filter={noFilter} />}>
<BlogExplorer posts={posts} topicSlugs={topicSlugs} />
</Suspense>
// blog-explorer.tsx
"use client";
export function BlogExplorer({ posts, topicSlugs }) {
// Reads ?topic=…&q=… from the URL
const filter = readFilter(useSearchParams(), topicSlugs);
return (
<>
<Intro /> {/* the heading, rendered again on the client */}
<BlogSearchForm filter={filter} />
<BlogResults posts={posts} filter={filter} />
</>
);
}The fix was to keep anything that doesn't need the URL out of the client component:
<Intro /> {/* the heading: plain server HTML, painted once */}
<Suspense fallback={<BlogSearchForm filter={noFilter} />}>
<BlogSearch topicSlugs={topicSlugs} />
</Suspense>
<Suspense fallback={<BlogResults posts={posts} filter={noFilter} />}>
<BlogResultsClient posts={posts} topicSlugs={topicSlugs} />
</Suspense>The heading is now server-rendered and never touched by hydration. The search box and results are client components, each with a static fallback that looks the same, so there's no layout shift either. LCP dropped to 0.75 seconds.
Splitting the page created a small bug of its own: click a topic, then type quickly, and the search box would put the old topic back. Two separate components were each writing the URL from their own, slightly stale copy of it. Each now merges its change into the live window.location, so neither overwrites the other.
4. Fonts: the invisible second paint
The site uses two web fonts: Bricolage Grotesque for headings and Inter for text. I'd set them to display: "swap" with no preloading. That's the advice you'll often read: show text immediately in a fallback font, then swap.
It passed every local test. Then CI failed. On the home page, LCP was 0.9 seconds in one Lighthouse run and 3.6 seconds in the next.
Same element, same page, different result. The cause was the swap itself. When the font arrived after the text had painted in the fallback, the text was drawn a second time, and Chrome counted that as a new, later Largest Contentful Paint. Whether it happened depended on a race between the font download and the first paint. As the home page gained more posts and images, the font lost the race more often.
The fix:
export const inter = Inter({
subsets: ["latin"],
variable: "--font-inter",
display: "optional", // never swap after the text has painted
preload: true, // start the download with the HTML
});display: "optional" gives the font a very short window (about 100 ms) to arrive. If it's late, the browser keeps the fallback for that page view instead of swapping, and the font is ready from cache on the next page. Preloading makes it arrive in time far more often. Next.js also generates a fallback font with matching metrics, so even when the fallback stays, nothing shifts.
The cost is about 125 KB of preloaded fonts, mostly Bricolage's variable optical-size axis (77 KB). The benefit is that text is painted exactly once, so in every run since, LCP and First Contentful Paint are the same moment.
5. When the measuring tool lies
Even after the font fix, Lighthouse CI kept flipping: one run in three put LCP at 3.1 to 3.5 seconds. I raised the runs from three to five, expecting a steadier median. It got worse: the article page failed three runs out of five.
So I compared the slow and fast runs, request by request. The same element was largest, the same files loaded before it painted, and in every run the text actually painted within about 150 milliseconds. The real page was fast. The number wasn't.
The cause is how Lighthouse simulates a slow phone. By default it loads the page at full speed, records what happened, then estimates how long it would have taken on a slow connection. On localhost, everything arrives almost instantly, so the JavaScript sometimes ran before the first paint. In those runs the simulation assumed the text had waited for all of the page's JavaScript over a slow 4G connection: 3.5 seconds, for a paint that really took 92 ms.
The fix was to stop simulating and actually slow things down:
"settings": {
"formFactor": "mobile",
"throttlingMethod": "devtools"
}With real network and CPU throttling during the run, the results became steady and realistic: LCP 1.6 to 2.0 seconds, performance 97 to 99, every run. Those numbers are higher than 0.75 seconds because they model a mid-range phone on 4G, not because the site got slower.
6. Caching, and the fix that broke development
I audited the caching headers Next.js sends, and almost everything was already right:
| What | Cache-Control |
|---|---|
| Pages | Cached at Vercel's edge until the next deploy |
| JS, CSS, fonts | max-age=31536000, immutable (names change with content) |
| Optimised images | immutable |
| Share images | immutable (the URL includes a content hash) |
| Icons and manifest | max-age=0, must-revalidate |
The icons and web manifest were the gap: browsers checked them again on every page view. They have fixed names, so they can't be immutable, but a day's cache with background refresh is safe. I added a headers() rule in next.config.ts, verified it in production, and moved on.
Later that day, my dev server was stuck in a reload loop.
There were no file changes and no errors, just a full page reload every fraction of a second. I recorded the dev server's hot-reload messages with a headless browser and found that every time the page connected, the server told it to restart its client code. Then I undid recent config changes one at a time on a fresh dev server. Reverting the fonts changed nothing. Removing the headers() rule stopped the loop.
In development, a custom headers rule that matches Next.js's generated icon and manifest routes made the dev server recompile on every request, which forced a reload. The headers only matter in production, so that's the only place they're applied now:
export default async function config(phase: string) {
if (phase === PHASE_DEVELOPMENT_SERVER) return nextConfig;
return { ...nextConfig, headers: iconCacheHeaders };
}7. The bugs that aren't speed but still break a fast site
Some of the most useful catches weren't about milliseconds at all.
- A page wider than the phone. On mobile, the blog's row of topic chips stretched the whole section to about 1,000 px, so the page scrolled sideways. A centred flex container was shrink-wrapping its content instead of filling the screen. Every centred container now has
w-full, so the chips scroll inside their own strip as designed. - Contrast. Axe found text that was hard to read: footer links at 4.3:1 (the minimum is 4.5:1), gold text on a dark panel at 1.49:1, a diagram label at 3.72:1. All fixed. (The W3C explains the rule in Understanding Contrast (Minimum) (opens in a new tab).) One accessibility test also failed at random, about one run in five. The home page's LCP badge fades in after 300 ms, and axe sometimes measured it mid-fade. The tests now wait for one-off animations to finish.
The results
| Page | LCP | Performance | Other scores |
|---|---|---|---|
| Home | 1.7s | 99 | All 100 |
| Blog | 1.7s | 99 | All 100 |
| Article | 1.7s | 99 | All 100 |
| About | 1.6s | 99 | All 100 |
| Courses | 1.7s | 99 | All 100 |
Medians of three Lighthouse CI runs on a mobile profile with real network and CPU throttling. "Other scores" are Accessibility, Best Practices and SEO. CLS is 0 on every page, total blocking time stays under 100 ms, and all 99 browser and accessibility tests pass on desktop, tablet and mobile.
What real visitors see
Lab numbers are a model. The real test is people's phones on people's networks, which is what Speed Insights collects.
What I'd tell you to take away
- Set budgets before you build, and make CI enforce them. Most of the bugs in this article were caught by an automated check. The one that wasn't, the dev reload loop, was exactly the one nothing was checking.
- Keep your LCP element out of client boundaries. Hydration repaints everything inside them.
- Fonts can move your LCP. If text is your largest element,
display: "optional"with preloading stops the second paint. - Check the list of image widths, not just
sizes. A gap forces the browser to download a much bigger file. - Question the measuring tool. Simulated throttling on localhost can report seconds of delay that never happened.
- Verify the boring parts in production, like caching headers. They fail silently.
The code for all of this lives in the site's repository, and every number above is checked again on each push. If you find something slow here, reply to the newsletter and tell me. I'd love to write the follow-up.
Geologist turned frontend engineer from Cameroon, based in Ghana. Makes web and mobile apps faster and writes down how. More about me

