Performance
perf/code-split
JavaScript is split by route, and features that most visits do not use load on demand with dynamic import().
moderatebrowserfe-perf-delivery
Why
Every kilobyte of JavaScript is downloaded, parsed and compiled before it helps, and the main thread is busy meanwhile: on mid-range phones that shows up as slow LCP and poor INP. A single bundle that holds the editor, the charts and the admin pages makes every visitor pay for all of them.
Fix
Let the framework split by route (Next.js, Nuxt, SvelteKit, Angular and Astro do it by default; React Router with lazy). Load heavy, rarely used parts on demand: const { Chart } = await import('./chart.js') on first open, React.lazy, Vue defineAsyncComponent, Angular @defer, Astro client:visible. Check the result with a bundle visualiser.
Examples
// good: the editor loads when someone opens it
openButton.addEventListener('click', async () => {
const { mountEditor } = await import('./editor.js')
mountEditor(container)
})Sources
Facts
- Id
perf/code-split- Severity
- moderate
- Check
- browser needs a rendered page:
audit --url - Applies to
page- Same problem in
- Lighthouse
unused-javascript - Taught by the skill
fe-perf-deliveryJavaScript, CSS and asset delivery- Since version
- 0.1.0
Read it in the terminal
npx github:dawidolko/frontend-skills explain perf/code-split