Performance: Content translation management
MEDIUM IMPACT
This affects page load speed and interaction responsiveness by managing how translated content is loaded and rendered.
import { useRouter } from 'next/router'; import en from '../locales/en.json'; import fr from '../locales/fr.json'; const translations = { en, fr }; export default function Page() { const { locale } = useRouter(); const t = translations[locale] || translations.en; return <div>{t.welcome}</div>; }
import translations from '../locales/all-translations.json'; export default function Page() { const t = translations['en']; return <div>{t.welcome}</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Import all translations at once | Minimal DOM changes | Multiple reflows due to delayed render | High paint cost due to large bundle | [X] Bad |
| Load only current locale translations | Minimal DOM changes | Single reflow on initial render | Low paint cost with smaller bundle | [OK] Good |
| Fetch translations on client after render | DOM updates after fetch | Reflow and layout shift on update | Medium paint cost with delayed content | [!] OK |
| Preload translations with static props | DOM ready with translations | Single reflow | Low paint cost, stable layout | [OK] Good |