Skip to the page

Concurrent React and Suspense · mid

Code splitting with lazy and Suspense

Code splitting moves code the first screen does not need into separate chunks loaded with dynamic import(); in React, lazy(() => import("./Chart")) plus a <Suspense> boundary loads a component only when it renders.

The notes

What you must know

  • const Chart = lazy(() => import("./Chart")) (the module must default-export the component). Render it inside <Suspense fallback={...}>.
  • Split by route first, then heavy widgets that are below the fold or behind an interaction (charts, rich editors, maps, modals).
  • Do not lazy-load above-the-fold or LCP content; it delays it.
  • Prefetch likely next chunks (on hover, on idle, or when visible) to avoid a spinner; avoid waterfalls of lazy chunks that load one after another.
  • Bundle analysis: find duplicate libraries, big date/lodash imports, barrel files that defeat tree shaking, unnecessary polyfills. Next.js has optimizePackageImports, next/dynamic, and the Turbopack Bundle Analyzer (16.1+, much improved in 16.4).
  • Place Suspense boundaries around meaningful sections so one loading chunk does not blank the page.
  • Measure LCP and INP before and after; smaller JavaScript also means less hydration work.

The red pen

Common traps: mistake → fix

  • Mistake: "Lazy-load everything"

    Fix: above-the-fold lazy loading hurts LCP and causes spinners.

  • Mistake: "Named imports are always tree-shaken"

    Fix: barrel files and side effects can pull in the whole library.

  • Mistake: "React.lazy works for named exports directly"

    Fix: it expects a default export (re-export or map the module).

Easy to hard

Questions interviewers ask, easy to hard

  1. Our initial JS is 1.8 MB. How do you cut it?
  2. Where do you put the Suspense boundary, and what does a spinner cost in UX?
  3. How do you prefetch a lazy chunk?
  4. Why might a named import pull in a whole library?
  5. What does next/dynamic add on top of React.lazy?

Practise

Practise with these questions

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview