1let downloaded = ["main.js (20kb)"];
2const lazyImport = (name, kb) => new Promise((resolve) =>
3 setTimeout(() => {
4 downloaded.push(name + ".js (" + kb + "kb)");
5 resolve(() => "rendered <" + name + "/>");
6 }, 100));
7async function app() {
8 console.log("first paint downloads:", downloaded.join(" + "));
9 console.log("user clicks the Reports tab…");
10 console.log("Suspense fallback: <Spinner/>");
11 const Chart = await lazyImport("Chart", 80);
12 console.log(Chart());
13 console.log("total downloaded:", downloaded.join(" + "));
14}
15app();
●Your app has a Reports tab with a heavy chart library — 80kb that most users never open. Yet every user downloads it before they see ANYTHING. Why is the login page paying for the charts?
Because a bundler ships one file by default: your whole app, everywhere, up front. React.lazy is the scalpel — and a download ledger will keep the score.
📦 Memory boxes
what the program is remembering right now
nothing remembered yet🖥️ What the computer shows
the answers the program prints out
nothing yet ▌