Skip to content

Load only the visitor's locale on web - #575

Merged
karanshukla merged 1 commit into
mainfrom
perf/lazy-locales
Nov 26, 2026
Merged

karanshukla merged 1 commit into
mainfrom
perf/lazy-locales

Conversation

@karanshukla

Copy link
Copy Markdown
Owner

Summary

Every locale JSON was bundled into the web __common chunk, so each visitor downloaded all five languages to read one. English stays bundled as the fallback. The others are split into their own chunks (i18n/loaders.ts) and fetched by an i18next backend the first time they are needed, so changeLanguage and loadLanguages resolve once the translations are in.

BrandProvider keeps the loading screen up until the locale LocaleProvider is about to apply has loaded. A non-English visitor never sees English first; the extra wait sits behind the spinner that is already there. Locale resolution moves unchanged from LocaleContext to utils/resolveLocale.ts so both contexts can call it.

Follow-up to #574.

Related issue

None.

Scope

  • API (OpenRestoApi)
  • Frontend (openresto-frontend)
  • Database migration
  • Docs / infra

Changes

  • __common goes from 1.2 MB to 783 KB raw. fr, es, de and nl are ~100 KB raw chunks each.
  • Jest has no ESM loader, so jest.setup.ts mocks @/i18n/loaders with require. Four tests read a French bundle through getFixedT("fr") and now await i18n.loadLanguages("fr") first. No app code reads a locale that way.
  • CLAUDE.md's i18n paragraph says where a new locale needs registering and the test gotcha above.

Local Lighthouse 13.6.0, mobile preset, expo export served with serve -s dist, English visitor, median of 3, against main after #574:

Home before Home after /locations before /locations after
Score 41 43 52 54
TBT 1.29 s 1.07 s 1.22 s 1.13 s
LCP 6.5 s 6.1 s 6.4 s 6.2 s
Transferred 866 KB 769 KB 867 KB 769 KB
JS (gzip) 626 KB 527 KB 628 KB 529 KB

Testing

  • OpenRestoApi.Tests pass locally (no API changes)
  • Frontend tests/build pass locally: npm run check, tsc --noEmit, check:doc-links, npm test and npm run test:android (311 suites each), expo export --platform web
  • CI passes (build, migration-check)
  • Manually verified the change end-to-end in Chromium, recording every DOM text change from first paint:
    • OPENRESTO_DEFAULT_LOCALE=de: only German ever rendered, including on a throttled 200 KB/s link; only the de chunk downloaded.
    • Stored fr pick: only French rendered; only the fr chunk downloaded.
    • Switching de → fr from the guest menu: fetches the fr chunk and flips the page, no errors.
    • Native not run here. import() is inlined by Metro off web, so the native bundle still carries every locale.

Migrations

  • This PR includes a database migration
  • Migration was tested locally (up and, if applicable, down)

Checklist

  • No secrets, connection strings, or credentials committed
  • Docs updated if API contracts or setup changed

Every locale JSON was bundled into the web __common chunk, so each visitor
downloaded all five languages to read one. English stays bundled as the
fallback; the others are split into their own chunks and fetched by an i18next
backend the first time they are needed.

BrandProvider now keeps the loading screen up until the locale LocaleProvider
is about to apply has loaded, so a non-English visitor never sees English
first. Locale resolution moves to utils/resolveLocale.ts unchanged so both
contexts can use it.
@karanshukla
karanshukla merged commit 3255cbe into main Nov 26, 2026
24 checks passed
@karanshukla
karanshukla deleted the perf/lazy-locales branch November 26, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant