Only the words a page needs
A multilingual Next.js app was sending its entire translation dictionary — thousands of strings — inside every page, to show a few hundred of them. I rebuilt how text reaches the browser.
- Type
- Engineering case study
- Focus
- Internationalisation and performance
- Stack
- Next.js App Router, React Server Components, TypeScript
- Scale
- Dozens of locales, thousands of strings
By the numbers
The problem
Interactive components need their text on the very first render — on the server and again while React hydrates — or visitors see raw keys or a flash of English. The simplest way to guarantee that was to embed the whole dictionary in every page.
It worked, but it put tens of kilobytes of compressed text into every HTML response, before the page could render. No single page used more than a small fraction of it.
Before and after
The whole dictionary, embedded in every page.
Just the page's own words. The rest arrives later, once, and stays cached.
How it works
The mistake that taught me the most
My first version preloaded the full dictionary at low priority. On a throttled phone it still competed with the page’s largest image and pushed Largest Contentful Paint back by more than a second and a half. Moving it to after load, at the next idle moment, removed the cost completely.
Guardrails
- The build fails if a page or layout isn’t wired up to receive its words, so nothing ships half-translated.
- An escape hatch for keys built from data, like a status code or a country name, so they can still travel with the page.
- Every string has an English fallback, so a missing translation shows readable text, never a raw key.
The rest of the locale system
- The locale lives in the URL, so every language version has its own indexable, shareable address, with canonical and hreflang links for search engines.
- Right-to-left support through logical CSS properties, with icons and arrows that mirror.
- Dates, numbers and prices formatted per language, with date locales loaded only when needed.
- Changing language in one tab updates the others too.
What I took from it
Measure what’s inside the HTML, not just the JavaScript bundle. The bytes that arrive before the page can render matter most — and they’re the easiest to forget.