Bundle size and build optimization
The esbuild/Vite-based application builder, how lazy loading shapes your bundles, and reading what's actually in them.
Deferrable views: the @defer blockLazy loading routes and components
Bundle size and build optimization
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Angular's current application builder uses esbuild and Vite — esbuild for fast production builds, Vite for a fast development server with instant module reloading.
- Every lazy-loading mechanism this roadmap has covered — loadComponent, loadChildren, @defer — directly shapes bundle size: code reachable only through one of them lands in its own separate chunk, not the main bundle.
- A bundle analyzer turns an abstract "my bundle is too big" complaint into a concrete, actionable one — showing exactly which dependencies and which of your own modules are taking up the most space.
Two different speed problems, two different tools
“Build tooling” in current Angular actually covers two genuinely separate concerns, solved by two different tools working together. esbuild handles production builds — compiling and bundling your actual deployed app — valued specifically for raw build speed, since a slow production build is friction every single deploy pays. Vite powers the development server — what runs while you’re actively editing code — valued for near-instant startup and module reloading, so a one-line change reflects in the browser almost immediately instead of waiting through a full rebuild. Knowing which half is doing what matters because they’re optimized for genuinely different things: a fast iterative dev loop isn’t the same problem as a fast, optimized production output, even though both now live under one application builder.
Lazy loading is a bundle-size decision, not just a loading-speed one
Every lazy-loading mechanism covered elsewhere in this roadmap directly
determines what ends up in which bundle. loadComponent/loadChildren split
whole routes and feature areas into their own chunks. @defer splits
individual template regions the same way, down to whatever dependencies that
specific block pulls in. None of this is automatic cleverness the bundler
performs on its own — it’s a direct consequence of where in your code a
dynamic import() appears. Code reachable only through one of those mechanisms
lands in its own chunk; code imported directly and unconditionally lands in
the main bundle, downloaded by every single user regardless of whether they
ever use it. Every decision about where to put a loadComponent or a @defer
boundary, covered in earlier lessons for their effect on loading speed, is
simultaneously a decision about bundle composition — the two are the same
mechanism viewed from two angles.
Turning “too big” into something you can act on
“The bundle is too big” isn’t actionable on its own — too big compared to what, and which part of it is actually the problem? A bundle analyzer answers that concretely: it visualizes exactly which dependencies, and which of your own modules, are contributing how many kilobytes to the final output. A surprisingly large third-party date-formatting library pulled in for one small feature, a utility imported in a way that defeats tree-shaking, an entire icon set bundled when only a handful of icons are actually used — these are the kinds of findings a bundle analysis surfaces, and none of them are visible from just watching a build complete and noting the final size number.
Tree-shaking: the part that happens even without lazy loading
Not every bundle-size win requires splitting code into chunks at all. Even inside the main bundle, a bundler can drop code that’s provably never used — tree-shaking — but only if it can actually prove that. A library built with side-effect-free ES modules and clearly-scoped exports lets a bundler see “nothing imports this function, so it’s safe to remove.” A library that executes top-level side effects on import, or is distributed only as one giant CommonJS blob, denies the bundler that guarantee — it has to assume the whole thing might matter, and includes all of it. This is why importing one function from a large utility library sometimes bloats a bundle far more than expected: the specific import syntax, and the library’s own packaging, both determine whether tree-shaking can actually do its job. A bundle analyzer, again, is how you’d actually notice this happening rather than suspect it in the abstract.
This lesson’s video is a conference talk directly from Angular’s own tech lead, covering the esbuild/Vite builder’s internals from the team that built it — strong authority on exactly how and why these tools were chosen. The linked “deeper” video is a more hands-on, practical walk through actually reading a bundle-size analysis on a real app, useful as the concrete follow-up to this lesson’s more architectural framing.
Check yourself
What's the practical difference, from a developer's day-to-day experience, between the esbuild half and the Vite half of Angular's current application builder?
esbuild handles the actual production build — compiling and bundling your app for deployment, valued for its raw build speed. Vite powers the development server, valued for near-instant startup and module reloading as you edit code during active development. They're solving two different problems — fast production output versus fast developer feedback loop — not two halves of the same job.
If a heavy charting library is only imported inside a component that's behind a @defer (on interaction) block, does it end up in the app's main bundle?
No — because @defer splits off the content (and its dependencies) behind that trigger into a separate chunk, the charting library ships in that chunk instead, fetched only when a user actually triggers the interaction. It's excluded from the main bundle entirely for any user who never interacts with that specific part of the UI.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.