Bundle & loading optimization
Code splitting, tree shaking, dynamic import, image formats (AVIF/WebP) and srcset, font loading without CLS. Kilobytes are a budget — spend them on purpose.
The mental model
Every kilobyte you ship is a loan the user repays with their battery, their data plan, and their attention. Bundle optimisation is deciding which bytes are worth borrowing, and when they must arrive.
The analogy: packing for a trip. A naive bundle is one giant suitcase you drag through the airport even though you need a jacket for the first ten minutes. Code splitting is packing a small carry-on with what you need on the plane and checking the rest. Tree shaking is refusing to pack the seven shirts you never wear. Preloading is having the jacket in your hand before you step outside instead of unzipping the bag on the pavement. And priority hints are telling the airline which bag comes off the belt first.
Why this exists. A browser can only render what has arrived and only run one script at a time on the main thread. JavaScript is uniquely expensive because it is not just downloaded — it is parsed, compiled, and executed, and all three happen on the thread that also handles taps. A 1MB image costs bandwidth. A 1MB JavaScript bundle costs bandwidth plus roughly 300–900ms of CPU on a mid-tier phone before anything responds. Without splitting and shaking, a user landing on the login page downloads the admin dashboard, the charting library, and the date picker for a form they will never open.
The idea that reorganises everything else: the browser's critical path is a dependency graph, and you are editing the graph, not just the file sizes. Making a file smaller helps. Removing it from the critical path helps far more.
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision