0
Challenge · 37Hooks & Effects
Code Splitting
Performanceused in ~60% of apps
By default your whole app compiles into one big JavaScript file the user must download before anything is interactive. A 1 MB bundle on a phone is seconds of blank screen. Code splitting breaks that file into chunks so the browser downloads only what the current view needs.
Core idea. Code splitting breaks one large bundle into smaller chunks that load on demand, so users download only the JavaScript for the view they're on. In React the mechanism is lazy() + dynamic import() + <Suspense>; the bundler emits a separate chunk for every dynamic import.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
/dist (chunks)1 network request
core.js (shell)
80 KBhome.chunk.js
60 KBprofile.chunk.js
140 KBsettings.chunk.js
90 KBThe bundler makes a chunk per route. Grey ones haven't been downloaded — they load only when visited.
Home page
A light feed list — loads fast.
downloaded so far (this session)0 KB / 370 KB full app
Code-split. Only the shell + Home loaded (140 KB) to start. Visit Profile/Settings and watch each chunk download on demand — and only once (revisits are cached). Never open Settings? You never pay its 90 KB.
↑ play a little first, then dig in