BBMM Technologies
← All articles
6 min readperformance, javascript, web, bundling

Reducing Bundle Size in Modern Web Apps

By Mykhailo Boichuk · Co-founder & Vice-President

In short

JavaScript is costlier than its byte size suggests because it must be downloaded, parsed, and executed before the page is interactive, and that work falls hardest on slower devices. Reducing bundle size means shipping only the code a page needs through code splitting, removing unused code with tree shaking, and being deliberate about dependencies, since a single careless import can dwarf the application’s own code.

JavaScript costs more than its size

A kilobyte of JavaScript is more expensive than a kilobyte of an image, because the script must be downloaded, parsed, compiled, and executed before it does anything, and much of that work blocks the main thread. The cost is felt most on lower-end devices, where parsing and execution are slow, so a bundle that feels fine on a developer’s machine can make a page sluggish or unresponsive on a typical phone. Bundle size is a proxy for this whole chain of work.

This is why reducing bundle size is one of the highest-impact performance levers on the web. Trimming the JavaScript a page ships improves not just download time but the parse and execution time that determines when the page becomes interactive.

Ship only what the page needs

The largest gains usually come from not shipping code a page does not use. Code splitting breaks the application into pieces that load on demand, so a visitor to one page does not download the code for every other page. Tree shaking removes code that is never referenced, so unused functions from a library do not ride along. Together they narrow the bundle to what the current page actually requires.

  • Split code so each page loads only what it needs, not the whole application.
  • Rely on tree shaking to drop code that is never referenced.
  • Defer loading code for features the user has not yet reached.

Dependencies are where bundles balloon

A single dependency added without thought can be larger than all the code a team wrote. A heavy library pulled in for one small function, or a package that bundles far more than is used, inflates the bundle out of proportion to the benefit. Auditing what each dependency costs, preferring smaller focused libraries, and sometimes writing the small amount of code yourself rather than importing a large package are how teams keep bundles in check.

Measure the bundle and what each dependency contributes to it, rather than guessing. The biggest contributor is frequently a library imported for a single feature, and seeing its cost in the bundle is what motivates finding a lighter path.

Key takeaways

  • JavaScript must be parsed and executed, so its cost exceeds its byte size, especially on slow devices.
  • Bundle size is a proxy for download, parse, and execution work that delays interactivity.
  • Code splitting ships only the code a page needs rather than the whole application.
  • Tree shaking removes code that is never referenced.
  • Dependencies are the common cause of bloat; measure and audit what each one costs.

Frequently asked questions

Why is JavaScript more expensive than other resources?
It must be downloaded, parsed, compiled, and executed before it does anything, and that work blocks the main thread, hitting slower devices hardest.
What is the difference between code splitting and tree shaking?
Code splitting loads only the code a given page needs on demand, while tree shaking removes code that is never referenced from what does ship.
Why do dependencies cause bundle bloat?
A single heavy library imported for one small function can exceed all the team’s own code, so auditing each dependency’s contribution is essential.

References

About the author

Mykhailo Boichuk

Co-founder & Vice-President

Mykhailo is an engineer who builds native applications and the systems behind them. He concentrates on macOS and iOS performance, local-first data architecture, and the synchronization problems that come with offline-capable software.