Remember the dist folder we dragged into Cloudflare in Session 1? That folder is the bundle β
everything the browser has to download, parse and run. Here's how we keep it small.
Below is padhle-utils, a pretend utility library β but every byte counted is the real
source code shown. Tick what your page actually uses, then shake the tree.
Real life: import _ from 'lodash' (CommonJS) ships the whole library.
import debounce from 'lodash/debounce' or lodash-es ships one function and its helpers.
Before adding any package, check its size on pkg-size.dev or bundlephobia.com.
Open DevTools β Network β JS first. Each button below downloads its code only when clicked. Watch a new file appear the first time β and not the second.
// React const TestAnalysis = lazy(() => import('./TestAnalysis')) <Suspense fallback={<Skeleton />}><TestAnalysis /></Suspense> // Next.js β plus: every page is already its own chunk const TestAnalysis = dynamic(() => import('./TestAnalysis'), { loading: () => <Skeleton /> }) // Plain JavaScript button.onclick = async () => { const { draw } = await import('./chart.js'); draw() }
These chunks are tiny (2β4 KB) so the demo stays light. In real apps the things worth splitting β a charting library, a PDF generator, a rich-text editor, a video player β are often hundreds of KB each.
The bundler names the output file after a hash of its contents:
A real one, from pw.live's HTML on 24 Sep 2026: webpack-899455d55a3e6270.js.
Same code β same name, forever. Changed code β new name. Hold that thought β it is the whole secret of caching.