Measure first:
npm i -D @next/bundle-analyzer
ANALYZE=true npm run build(wrap your config with withBundleAnalyzer per its README). It opens a treemap per route.
Usual suspects on a landing page:
- The chart library. Recharts/Chart.js are big. Load it lazily with
next/dynamicso it's not in first load, or render a static SVG if the chart never changes. import * as Icons from ...or an icon barrel. Import icons one by one.- A
"use client"at the top of page.tsx or layout.tsx pulls every import below it into the bundle. Push it down to the smallest interactive component.
treemap shows recharts 140kB and date-fns-tz 60kB (for a footer date??). Dynamic import for the chart brought it to 330 kB. magnus_e · edited