Skip to content
BENIBIX Learn

Minification vs Tree Shaking

Both make code files smaller. Minification squeezes code by cutting spaces and long names. Tree shaking drops whole parts of code that are never used.

Development🌐 Web Development

Minification

Making code smaller. It cuts spaces, notes and long names, and the code still works.

Minification makes code files smaller. It removes all the things the computer does not need. It strips spaces, line breaks and comments, and it swaps long names for one letter. The code still runs the same, but it is hard for people to read. Smaller files download faster, which matters most on phones. Build tools minify JavaScript and CSS before a site goes live.

Example
Jack's 180 KB script shrinks to 60 KB once it is minified. The page loads much faster on a phone.
Why it matters
Each byte has to travel to each visitor. Making files smaller is free speed.
Full entry
Development🌐 Web Development

Tree Shaking

A build step that drops code you imported but never used.

Tree shaking is a build step that removes code you import but never use. A bundler follows which functions each file really calls. Anything that is never reached is left out of the final bundle. This matters because big libraries may hold hundreds of functions when you use three. It works best with modern import and export syntax.

Example
Emma imports one date function from a large library. Tree shaking keeps that one function and drops the other 200.
Why it matters
It keeps bundles small even when you use big libraries. Smaller bundles mean faster pages.
Full entry

In one line

Minification
Making code smaller. It cuts spaces, notes and long names, and the code still works.
Tree Shaking
A build step that drops code you imported but never used.