Glossary Development

Minification

Minification removes whitespace, comments and other characters that are not needed to run code, making files smaller and faster to send.

Last reviewed:

AdSense Placeholder
Slot: header_reference_page

In more detail

It is the opposite of formatting or beautifying, which add indentation to make code readable. Minified code is not secure or secret, only compact; use formatters for HTML, JavaScript and SQL when you need to read someone else's minified file. Beyond stripping whitespace and comments, JavaScript minifiers shorten local variable names (called mangling) and remove unreachable code. Because they must understand the language, they work by parsing, not by blind find-and-replace.

Why it matters

Smaller files download faster and use less bandwidth, which helps page speed, especially on slow mobile connections. Minification is separate from compression: servers usually also compress files with gzip or Brotli, and the two savings add up. Typical problems come from minifying carelessly. Removing a line break can change what code means in languages with automatic semicolon insertion, a broken build can ship unreadable error traces, and people sometimes assume minified code is hidden. Keep the readable source, minify only for release, and publish a source map if you want debugging to stay possible.

Example

This CSS is 48 bytes:

body {
  margin: 0;
  padding: 0; /* reset */
}

Minified it is body{margin:0;padding:0}, 24 bytes, half the size, with identical behaviour. The same idea applies to data: compact a JSON file with the JSON Minifier & Compressor, and bring it back to a readable layout with a formatter such as the CSS Formatter for CSS, the JavaScript Beautifier for JavaScript, the HTML Formatter for HTML or the SQL Formatter for SQL.

Common confusion

Minifying is not obfuscation or encryption: the logic is all still there, just harder for a person to read. Compacting JSON only removes the spaces and line breaks between its tokens.

AdSense Placeholder
Slot: footer_leaderboard