JavaScript Minifier
Minify JavaScript by removing whitespace, line breaks, and comments for smaller files, without renaming your code.
JavaScript Minifier tool
Example
Input: function add(a, b) { / // return the sum / return a + b; / }
Result: function add(a,b){return a+b;}
Comments and whitespace that the code does not need are removed, while string and regular expression contents are left untouched.
- Paste your JavaScript source code into the JavaScript panel.
- The minifier processes your code and displays the compressed output instantly in the Minified JavaScript panel.
- Compare the two panels to confirm the code is intact and noticeably shorter.
- Verify that the minified code does not include any comments or unnecessary whitespace.
- Click the copy button to copy the minified JavaScript for deployment in your production environment.
How JavaScript Minification Works
A JavaScript minifier shrinks a script by removing comments and whitespace that the engine does not need. A small add function with a comment above it becomes function add(a,b){return a+b;} and runs exactly the same.
Doing this safely takes more than deleting spaces. The tool reads your code as tokens, so it knows what is inside a string, a template literal or a regular expression, and it leaves those contents alone. It keeps a space wherever two tokens would otherwise merge, as in a + +b or return x. It also keeps a line break wherever automatic semicolon insertion depends on it, so code written without semicolons still works.
It does not rename variables, remove unused code or rewrite expressions. Tools such as Terser and esbuild do that and produce smaller files, but their output is hard to trace back to your source. Here every name stays the same, so an error message from the minified file still makes sense. Hashbang lines (#!) and comments that start with /*! are kept, since those usually carry license notices.
Minification here works in one direction only. If you paste code into the Minified JavaScript panel, the tool tells you it does not beautify; use a code formatter such as Prettier for that. The same careful approach is used by the CSS Minifier and the JSON Minifier.
Frequently Asked Questions
Related Tools
CSS Minifier
Minify CSS by removing whitespace, comments, and redundant code to reduce file size.
Developer ToolsHTML Minifier
Minify HTML by removing comments and collapsing whitespace between tags and inside tags to reduce document size.
Developer ToolsJSON Formatter and Validator
Format, validate, beautify, and minify JSON data with a collapsible tree view and line-and-column error detection.
Developer ToolsBase64 Encode and Decode
Encode text to Base64 and decode Base64 strings back to readable text, with full UTF-8 support.
Developer Tools