Skip to content

JavaScript Minifier

Minify JavaScript by removing whitespace, line breaks, and comments for smaller files, without renaming your code.

JavaScript Minifier tool

Loading...

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.

  1. Paste your JavaScript source code into the JavaScript panel.
  2. The minifier processes your code and displays the compressed output instantly in the Minified JavaScript panel.
  3. Compare the two panels to confirm the code is intact and noticeably shorter.
  4. Verify that the minified code does not include any comments or unnecessary whitespace.
  5. 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

Minifying removes characters the engine does not need, to make the file smaller. Obfuscating deliberately makes code hard to understand, by renaming things, adding confusing structures and encoding strings. This tool only minifies and never renames, so the output stays readable to anyone who formats it again.
This tool is careful: it understands strings, template literals, regex literals and automatic semicolon insertion, and it keeps any space or line break that affects meaning. Code that reads its own source, for example through Function.prototype.toString, could still behave differently. As with any build step, run your tests on the minified output before you ship it.
Some line breaks carry meaning. JavaScript inserts a semicolon at certain line ends, so removing the break after return, for example, can change what the code does. When the tool cannot prove a break is safe to drop, it keeps it. Adding semicolons in your source lets it remove more.
It depends on your code. Files with many comments and deep indentation shrink the most, while code that is already compact shrinks little. Because names are not shortened, the result will be larger than Terser or esbuild output. Compare the lengths of the two panels to see the saving for your file.
No. Work with readable source during development and minify copies for production. If you use a build tool, it can also create source maps, which let browser developer tools show your original code while running the minified file. This online tool is best for quick one-off jobs such as a small widget or an inline script.

Related Tools

CSS Minifier

Minify CSS by removing whitespace, comments, and redundant code to reduce file size.

Developer Tools

HTML Minifier

Minify HTML by removing comments and collapsing whitespace between tags and inside tags to reduce document size.

Developer Tools

JSON Formatter and Validator

Format, validate, beautify, and minify JSON data with a collapsible tree view and line-and-column error detection.

Developer Tools

Base64 Encode and Decode

Encode text to Base64 and decode Base64 strings back to readable text, with full UTF-8 support.

Developer Tools

Regex Tester

Test regular expressions with real-time match highlighting, group capture display, and a pattern library.

Developer Tools

JSON Minifier

Minify JSON by removing whitespace and formatting for compact, production-ready output.

Developer Tools