JS Minifier
Paste your JavaScript and get minified output instantly — single-line and multi-line comments are removed, whitespace is collapsed, and string literals are left untouched. The tool runs entirely in your browser so your code never leaves your device. Smaller JavaScript files download faster, parse more quickly and improve your site's performance scores.
How to Use the JS Minifier
Paste your JavaScript source code into the Input JavaScript box and click Minify JS. The minified output appears below along with a byte-size comparison and the percentage saved. Click Copy Minified JS to copy the result and use it in your project. For production deployments, consider integrating an AST-based minifier like Terser into your build pipeline for maximum compression.
What JavaScript Minification Does
This minifier performs safe, non-destructive transformations:
- Removes single-line comments — everything from
//to end-of-line is stripped (comments inside strings are preserved). - Removes multi-line comments — everything between
/*and*/is stripped (comments inside strings are preserved). - Collapses whitespace — multiple spaces, tabs and newlines are collapsed to a single space or removed entirely where safe.
- Preserves string literals — content inside single quotes, double quotes and template literals is left exactly as-is.
- Preserves regex literals — the parser detects regex context and avoids stripping
/characters that are part of a regular expression.
Note: This is basic (lexer-level) minification only. Variable renaming, dead-code elimination and other advanced optimisations require a full AST-based tool such as Terser or Google Closure Compiler.
Basic vs Full Minification
| Feature | Basic (this tool) | Full (Terser / Closure) |
|---|---|---|
| Remove comments | Yes | Yes |
| Collapse whitespace | Yes | Yes |
| Rename variables | No | Yes |
| Dead-code elimination | No | Yes |
| Inline short functions | No | Yes |
| Typical savings | 10–30% | 40–60% |
| Risk of breakage | Very low | Low (with config) |
When to Minify JavaScript
Always minify JavaScript before pushing to production. Never minify your working source files — instead, keep the readable version in your repository and generate the minified build automatically. Tools like Vite, esbuild, Webpack and Rollup all minify JavaScript by default in production mode. Use this online minifier for quick snippets, third-party scripts, or when you're working outside a build pipeline.
Frequently Asked Questions
What is JavaScript minification?
JavaScript minification removes comments, extra whitespace and newlines from source code without changing what the code does. The result downloads and parses faster in the browser, improving page performance.
Does basic minification break my code?
No — removing comments and collapsing whitespace is completely safe and doesn't alter how JavaScript executes. This tool does not rename variables or restructure code, so the risk of breakage is extremely low.
How much file size can I save?
Basic comment and whitespace removal saves 10–30% depending on how heavily commented your code is. Full AST-based minification with variable renaming can save 40–60%, and Gzip on top pushes total savings to 70–85%.
What's the difference between minification and obfuscation?
Minification reduces file size while keeping code structurally readable. Obfuscation deliberately makes code hard to understand by scrambling variable names and encoding strings. Minified code can be re-formatted with a beautifier; obfuscated code is intentionally resistant to reverse-engineering.