Code splitting and dynamic imports to reduce bundle size.
CRITICAL priority - Reduces Time to Interactive and Largest Contentful Paint.
Key patterns:
- Dynamic imports (next/dynamic or React.lazy)
- Defer third-party scripts
- Conditional module loading
- Preload on hover for perceived speed
When to split:
- Components >50KB bundled
- Heavy libraries (Monaco, Chart.js, PDF viewers)
- Behind user interaction (modals, tabs)
Next.js Apps (next/dynamic)
Defer Third-Party Libraries
Load analytics and tracking after hydration:
Next.js:
Vite:
Conditional Module Loading
Load modules only when features are activated:
Improve perceived performance by preloading on hover:
Split these aggressively:
- Monaco Editor (~300KB)
- Chart.js (~200KB)
- PDF.js (~150KB)
- Rich text editors (Slate, Draft.js)
- Video players
- Map libraries (Mapbox, Leaflet)
Routes are automatically code-split in Next.js App Router:
Manual Chunk Configuration (Vite)
For more detailed technical guidance, see these reference files: