About javascript minifier / compressor
Minifying JavaScript removes comments and unnecessary whitespace so scripts download and parse faster.
Simple versus full minifiers
This tool strips comments and whitespace. Build tools such as esbuild and Terser also shorten variable names and remove unused code, which saves more.
Test afterwards
Run your app after minifying. Strings and regular expressions are preserved, but automatic semicolon insertion can sometimes change behaviour in unusual code.
A worked example
A script with comments, blank lines and indentation is reduced to a compact block. A 12 KB file may drop to around 8 KB. Build tools can go further by shortening variable names and removing unused code, so use them for production bundles.
Safety tips
- Always end statements with semicolons in code you plan to minify.
- Keep the unminified source and a source map.
- Test in the browsers you support after minifying.
