Skip to content

Menu

JS Minifier / Beautifier

Beautify or minify JavaScript. Strip comments and whitespace with character count.

Runs entirely in your browserFormattersFree, no sign-up
Loading tool

01What is JS Minifier / Beautifier?

Sometimes you just need a small script squeezed down, or a minified blob made readable again, without setting up a build. This tool does both. It has a Minify mode and a Beautify mode, and both work on JavaScript tokens instead of raw text. That is the difference between a tool that saves bytes and one that quietly breaks your code. The tokenizer knows single- and double-quoted strings, template literals with nested ${...} expressions, comments, numbers (BigInt and numeric separators like 1_000n included), private #fields and every operator. It also tells a / that starts a regex from a / that divides, by looking at the previous token. After words like return or typeof, a slash opens a regex. Minify drops comments and any whitespace that isn't needed. It keeps one space only where two tokens would otherwise merge into something else. Think return x, or a - -b, which would turn into a decrement if written a--b. Comments that start with /*! are kept, which is the usual convention for licence headers. Strings, template text and regexes are copied byte for byte. Line breaks get special treatment. The automatic semicolon insertion rules in the ECMAScript spec can depend on a newline. So the minifier only removes a line break when the token before it can't end a statement, or the token after it can't start one. Here is a worked case: a function whose body is return, a newline, then 42; minifies to function f(){return\n42;}. The break after return stays, because removing it would make the function return 42 instead of undefined. Beautify re-indents by brace depth with 2 or 4 spaces. It puts statements and block contents on their own lines and keeps your existing line breaks. It doesn't add spaces around operators, so x>1 stays x>1. Limits, plainly. Minify doesn't rename variables, remove dead code or rewrite expressions. Terser or esbuild will produce smaller files for production. Beautify can't recover original names from a mangled bundle, which needs a source map. If the input has an unterminated string, template, regex or comment, you get an error such as "Unterminated string literal" instead of a half-processed result. Below the output you see both character counts and the percentage saved. Your code is processed inside the page and isn't uploaded.

Frontend developers who need to minify or read a small script quickly without a build tool, such as a bookmarklet or tag-manager snippet. The tool runs entirely in your browser, so your data never leaves your device.

02How to use JS Minifier / Beautifier

  1. Paste your JavaScript into the Input box
  2. Pick the Beautify or Minify tab, and choose 2 or 4 space indentation if you're beautifying
  3. Click Beautify or Minify to run it
  4. Read the Output and check the character counts and percentage saved underneath
  5. Click Copy to put the result on your clipboard

03Worked examples

Input: // add function add(a, b) { return a + b; } const x = add(1, 2); (Minify)
Result: function add(a,b){return a+b;} const x=add(1,2);
Comments and spaces go, but names are not shortened: this is whitespace minification, not mangling.
Input: function f() { return 42; } (Minify)
Result: function f(){return 42;}
The break after return is kept because JavaScript inserts a semicolon there; the function returns undefined before and after minifying.
Input: const re = /\/\/ keep/g; const s = "a // b"; const t = `x ${1 + 1}`; (Minify)
Result: const re=/\/\/ keep/g;const s="a // b";const t=`x ${1+1}`;
The // inside the regex and the string is not treated as a comment, and spacing inside strings and template text is preserved.
Input: a = b + +c; d = e - -f; (Minify)
Result: a=b+ +c;d=e- -f;
One space survives in each line because "b++c" and "e--f" would be read as increment and decrement operators.
Input: /*! MIT License */ /* helper */ const n = 1_000n; (Minify)
Result: /*! MIT License */ const n=1_000n;
The /*! licence comment stays, the ordinary comment goes, and the BigInt with a numeric separator is copied as one token.
Input: function f(x){if(x>1){return x*2}else{return 0}} (Beautify, indent 2)
Result: function f(x) { if(x>1) { return x*2 } else { return 0 } }
Beautify re-indents by braces and lines; it doesn't add spaces around operators like > or *.

04Common use cases

  • Shrinking a bookmarklet so it fits comfortably in a browser bookmark URL
  • Minifying a small inline <script> for a landing page that has no build step
  • Re-indenting a one-line snippet copied from a production bundle while chasing a bug in DevTools
  • Stripping comments from a tracking snippet before pasting it into a tag manager or CMS field
  • Checking that a semicolon-free file keeps its meaning after minification
  • Seeing how much of a hand-written script is comments and whitespace from the character counts

05Tips

  • Start licence or attribution comments with /*! and Minify keeps them while dropping all other comments
  • A newline that looks wasted in minified output is usually guarding against automatic semicolon insertion, so leave it
  • For production bundles use Terser or esbuild with mangling on. This tool only removes comments and whitespace
  • Beautify keeps operator spacing as written, so run Prettier afterwards if you want fully normalised style
  • An "Unterminated string literal" error usually means a paste got cut off, so check the end of your input first

06Related concepts

Terser, esbuild, Source maps, Tree shaking.

Frequently Asked Questions

What is JS Minifier / Beautifier?

JS Minifier / Beautifier is a free, browser-based developer tool on AIDToolStack. Beautify or minify JavaScript. Strip comments and whitespace with character count. It requires no installation or sign-up and works entirely in your browser.

Is JS Minifier / Beautifier free to use?

Yes. No sign-up, no fees and no usage cap.

Does JS Minifier / Beautifier store my data?

No. It runs in your browser; nothing is uploaded.

Related Tools

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe