What Is Code Minification?
Minification is the process of removing all unnecessary characters from source code without changing its behavior. This includes whitespace, comments, and sometimes shortening variable names. The result is a smaller file that downloads faster and parses quicker by the browser.
For production websites, minification is essential. A minified JavaScript file can be 60-80% smaller than the original, directly improving Core Web Vitals and user experience. Every major framework — React, Vue, Angular, Svelte — ships with a minification step in its production build.
Supported Languages & Libraries
- JavaScript: Powered by
Terser, the industry-standard minifier used by Webpack, Rollup, and Vite. It compresses code and mangles variable names safely [citation:1]. - CSS: Powered by
CSSO, which performs structural optimizations beyond simple whitespace removal — merging rules and shortening colors. - HTML: Powered by
html-minifier-terser(browser build), which collapses whitespace, removes comments, and can minify inline CSS/JS [citation:4][citation:12]. - JSON: Uses the browser's native
JSON.parseandJSON.stringifyfor guaranteed correctness. - SQL: Uses
sql-formatterin minify mode, supporting multiple dialects including MySQL, PostgreSQL, and T-SQL.
Safe Mode vs Aggressive Mode
Not all code is safe to aggressively minify. Some JavaScript relies on function names (for Function.prototype.name), class names (for framework reflection), or specific whitespace inside template literals. Safe Mode disables name mangling and preserves these properties. Aggressive Mode enables full Terser mangling for maximum compression.
| Mode | Best For |
|---|---|
| Safe Mode | Production code that uses reflection, function names, or class names. Recommended default. |
| Aggressive Mode | Code you control completely and can test thoroughly. Maximum compression. |
Why Browser-Side Minification?
Most online minifiers upload your code to their server. That is a privacy risk, especially for proprietary code. This tool loads the minification libraries directly in your browser and processes everything locally. Your code never leaves your device.
Minification Best Practices
- Minify last. Run minification as the final step before deployment, after all tests pass.
- Keep source maps. If you debug production code, generate source maps alongside minified files.
- Use Safe Mode by default. Only switch to Aggressive Mode when you understand the risks.
- Combine with gzip/brotli. Minification removes characters; compression algorithms like gzip further reduce size. Use both.
- Test in a browser. Always load the minified file in a real browser and check for console errors.
Frequently Asked Questions
Related Tools
External Resources
- Terser API Reference — JS minifier documentation
- html-minifier-terser on GitHub — HTML minifier source
- CSSO on GitHub — CSS optimizer
- sql-formatter on GitHub — SQL formatter