Skip to content
BENIBIX Learn

Minification

Development🌐 Web DevelopmentBuild Tools

Also known as Minify, Minifier, Code Minification

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

Think of it like

Think of it like squeezing the air out of a bag of clothes. Same clothes, much smaller bag.

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.

Definition

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 code

javascript
// before
function addNumbers(first, second) {
  return first + second;
}
// after
function a(n,r){return n+r}
Same function, a fraction of the size.

Common mistake

Trying to debug the minified file. Use a source map to see the original code instead.

Key takeaways

  1. 1
    Strip the extras. Spaces, comments, long names.
  2. 2
    Same behaviour. It runs exactly the same.
  3. 3
    Smaller downloads. Faster pages, mostly on phones.

Compare