Static Sites & Deployment

Minification

Definition

Minification rewrites source text into the shortest form that still parses the same way. Whitespace and comments go first, then JavaScript minifiers rename local variables to single letters, collapse expressions and remove code that can never run. A CSS minifier does something similar: it drops the last semicolon in a block, shortens #ffffff to #fff, and merges duplicate rules. Typical savings are 30 to 60 per cent before compression, so a 300 KB script commonly lands around 120 KB. The output is unreadable to humans, which is why builds emit a source map beside it so browser dev tools can show the original. Minification is lossless as far as behaviour goes — the program does exactly what it did before — and it normally runs as part of asset bundling rather than as a separate chore.

Why It Matters

Smaller files arrive sooner, and on a page held up by a render-blocking stylesheet that difference is visible rather than theoretical. Minification stacks with transport compression instead of competing with it: a 300 KB script might minify to 120 KB and then travel as roughly 38 KB once gzip compression has done its work, where the unminified original would have been near 70 KB on the wire. That is a saving on every request from every visitor, paid for once at build time. It also has a quiet security benefit, since comments in source files have a habit of containing internal URLs and the odd stray credential. What it does not do is make slow code fast — it only makes the download shorter.

How It Works

A minifier parses the file properly rather than running text substitutions, builds a syntax tree, and prints that tree back with the shortest legal formatting. Terser and esbuild handle JavaScript, cssnano and Lightning CSS handle stylesheets, and html-minifier trims markup. Renaming is confined to local scope, because anything reachable from outside the file, such as a global function or a CSS class name used in the HTML, has to keep its name. A source map is written alongside, referenced by a comment at the end of the file, mapping each minified position back to a line and column in the original. The build step then writes the result into the output folder under its hashed filename, and only that folder is uploaded.

Real-World Example

A freelancer publishes a client dashboard as a static export on 99helpers at vale-metrics.99helpers.site. The unminified build is 1.4 MB of JavaScript and 210 KB of CSS; with minification turned on it becomes 480 KB and 62 KB, and after Brotli on the wire the first load is a shade over 160 KB. The dashboard behaves exactly as before. The only visible change is that it stops feeling sluggish on the sales team's phones.

Common Mistakes

  • Shipping the development build because it was the one already sitting in the folder — no minification, no tree shaking, and often three times the necessary bytes
  • Uploading without the source maps and then trying to debug a live error from single-letter variable names
  • Minifying HTML that depends on whitespace between inline elements — words run together and layouts shift, because that whitespace was doing visible work

Related Terms

Put a file online in seconds

Drop in a document, an image, a page or a whole static website and share the link — free, with no build step and no server to set up.

Host a file free →