DEV Community

desgh white
desgh white

Posted on

Lazy-Loading Translated Content Without Layout Shift

Shipping all translation bundles upfront bloats the initial load. Lazy-loading them on route change is lighter but introduces layout shift when a shorter English placeholder is replaced by a longer Polish string.

Reserve space with CSS

The cheapest fix: set min-height on text containers based on the longest known translation. This is impractical at scale, but for hero headings and CTAs it eliminates the worst shifts:

.hero-title { min-height: 3.6em; } /* covers PL two-line wrap */
Enter fullscreen mode Exit fullscreen mode

Skeleton with locale-aware line count

Better: the server returns a skeleton hint per locale — how many lines the translated block typically occupies:

{ "hero_title": { "lines": { "en": 1, "pl": 2, "de": 2 } } }
Enter fullscreen mode Exit fullscreen mode

The client renders a placeholder with the right number of skeleton lines before the bundle loads.

Preloading the likely locale

If the user's Accept-Language header or a cookie declares pl, preload the Polish bundle alongside the shell:

<link rel="modulepreload" href="/i18n/pl.js">
Enter fullscreen mode Exit fullscreen mode

A multi-locale platform like Nowe Kasyno that targets Polish users cannot afford a visible flash of English before the Polish strings arrive — it signals that localisation is an afterthought.

Font considerations

Polish uses ą ć ę ł ń ó ś ź ż, which are present in most Latin-extended fonts but not in every subset. If you subset Google Fonts, include latin-ext. Missing glyphs fall back to a system font with different metrics, causing — again — layout shift.

Takeaway

Lazy i18n is a performance win only if you pre-calculate the layout cost. Otherwise you trade load time for visual instability.

Top comments (0)