piapia123
en

Minify or Beautify JavaScript

Format

Everything runs locally in your browser — nothing is uploaded

Input
Drop a file here to load its contents
Output

Two directions in one tool. Minify strips comments and redundant whitespace down to as few lines as possible; beautify re-lays out code that was squeezed onto one line, using braces and semicolons as the structure. Both are pure text transformations with no parsing — which is why minifying never renames a variable or removes dead code (that is a bundler or obfuscator job), and also why it can never break your code: strings and template literals are carried through verbatim, and nothing but whitespace is ever changed. Minifying has one easily-missed rule: removing a line comment must keep its newline — `return // note` followed by `a` means `return;` plus a statement (undefined) under automatic semicolon insertion, and deleting the newline turns it into `return a`, which returns a value instead. The same limitation as beautifying applies: brackets inside regular expression literals are read as structure.

Features

  • The output is syntax-highlighted, with keywords, strings and comments colour-coded
  • Indents by brace depth, with the closing brace returned to the matching level
  • Breaks lines after semicolons, but not inside for (;;) where they are separators
  • Keeps } else {, } catch { and } finally { on one line
  • Object literals stay on a single line when they have no semicolon and are short, while code blocks are expanded
  • Class bodies are always expanded across lines
  • Strings, template literals (including nested templates and ${} expressions) and comments are preserved verbatim
  • A line comment always forces a line break, so following code can never be commented out
  • Whitespace is only added where the grammar leaves no doubt: after commas and between control keywords and their parenthesis
  • Known limitation: without lexical analysis, brackets inside regular expression literals are read as structure
  • Minify mode: strips comments, line breaks and indentation down to as few lines as possible
  • Minifying keeps /*! and //! licence comments — stripping someone’s copyright notice is a legal risk
  • Minifying never fuses two tokens: return a, a + +b and 1 .toString() all stay parseable
  • Removing a line comment keeps its newline, so a return statement cannot silently change meaning
  • No variable renaming and no dead-code elimination (that is an obfuscator’s job)

How to use

  1. Paste your JavaScript into the input box
  2. Choose Minify to squeeze it onto few lines, or Format to lay it out
  3. In format mode you can also pick the indentation width
  4. Click Copy, or Download to save it as a .js file

FAQ

Why do regular expressions throw the layout off?
Telling a division slash from the start of a regular expression needs a full lexer, including unary versus binary operators. Guessing wrong swallows the rest of the line as a pattern, so instead of guessing the limitation is stated plainly: indentation may be off when a regular expression contains brackets.
Why is the spacing around operators left alone?
Spacing a=b out requires knowing whether a minus is unary or binary, as in a - -b, i++ or x=-1. That is lexical analysis again, and guessing wrong can change what the code means. This tool sticks to indentation so it cannot break your code by guessing.
Does minifying change how the code behaves?
No. Minifying only removes comments and whitespace and does not touch a single character of code — semicolons, brackets, operators and string contents all stay as they are. It does keep the newline that ends a line comment: with `return // note` followed by `a`, that newline carries meaning in JavaScript (automatic semicolon insertion), and removing it turns the line into `return a`, changing a function from returning undefined to returning a value. The minified output is safe to run as-is.
Can I use minifying as obfuscation?
No, and please do not. It does not rename variables, remove dead code or rewrite control flow — variable names come out exactly as they went in, just without the whitespace and comments around them. Real obfuscation needs a parser and an understanding of scope, and the result is something you can no longer debug. Use it to make a file smaller, nothing more.
Can it change how my code behaves?
Nothing but whitespace is touched: no semicolon, bracket, operator or string content is altered. You can verify this yourself by stripping all whitespace from the input and the output and comparing the two.
Is my code uploaded anywhere?
No. Everything runs in your browser memory, the page makes no network requests, and it works offline.

Related tools