Developer Tools

JavaScript Formatter and Minifier

This tool reindents JavaScript for reading and strips it down for shipping. The minifier is the part worth explaining: most browser-based minifiers are a stack of regular expressions that cannot tell code from a string, so a URL inside quotes loses everything after its double slash. This one tracks whether it is inside a string, template, regex or comment before removing anything.

Runs entirely in your browser — nothing you paste is uploaded.

Mode

Reindent so the structure is readable.

Indent

How to

How to use the JavaScript Formatter

  1. 1

    Paste your JavaScript

    Type, paste, or load a .js file. Formatting runs as you type with no button to press.

  2. 2

    Choose beautify or minify

    Beautify reindents for reading. Minify strips whitespace and comments while leaving anything inside a string or regular expression untouched.

  3. 3

    Set your preferences

    Pick an indent size or tabs, and choose a brace style. For minifying, decide whether comments should go.

  4. 4

    Check the saving and copy

    The byte counts show what the minification bought you. Copy the result or download it as a file.

Examples

JavaScript Formatter examples

A URL inside a string

Input
const url = "https://example.com/api";
Output
const url="https://example.com/api";

A regex-based minifier treats the double slash as the start of a comment and deletes the rest of the line, producing an unterminated string. Tracking string context avoids that entirely.

A template literal

Input
const t = `line one indented`;
Output
const t=`line one indented`;

The indentation inside a template literal is part of the value. Collapsing it changes what the program outputs, which is why templates are copied through byte for byte.

A regular expression

Input
const re = /a\/b/g;
Output
const re=/a\/b/g;

The escaped slash inside the regex would end a comment for a naive scanner. Distinguishing division from a regex literal requires looking at the preceding token, which this minifier does.

Why use it

What the JavaScript Formatter gives you

Minification that cannot corrupt your code

Strings, template literals, regular expressions and comments are identified before anything is removed, so nothing inside them is ever touched.

Respects automatic semicolon insertion

Line breaks that carry meaning are kept, so code written without semicolons still behaves the same after minifying.

Backed by js-beautify

The beautify path uses a well-established library rather than a home-made reindenter, so unusual syntax is handled properly.

Nothing is uploaded

Proprietary source stays in your browser. No request is made and no copy is kept.

Good to know

JavaScript Formatter limitations

  • This is a whitespace minifier, not a compressor. It does not rename variables, remove dead code or bundle modules — use a real build tool for that.
  • Very old or non-standard syntax may confuse the beautifier, though the minifier only needs to find string boundaries.
  • Minified output is valid but not obfuscated. Anyone can reformat it back into readable code.
  • Extremely large files are held in memory and may make the browser sluggish.

Summary

JavaScript Formatter in short

  • The minifier understands string, template, regex and comment context.
  • A URL inside a string survives, where regex-based minifiers truncate it.
  • Line breaks are preserved where automatic semicolon insertion depends on them.
  • Minification here removes whitespace only — it does not rename or obfuscate.
  • Everything runs in your browser.

FAQ

JavaScript Formatter questions

Why do some minifiers break URLs in strings?

They strip comments with a regular expression that looks for two slashes. The double slash in https:// matches, so everything after it on that line is deleted — leaving an unterminated string and code that will not parse.

Is minified code protected from being read?

No. Minifying removes whitespace and comments, and any formatter turns it straight back into readable code. Obfuscation is a different process, and even that only slows a determined reader down.

Will minifying break code written without semicolons?

Not here. JavaScript inserts semicolons at certain line breaks, so removing those breaks changes behaviour. Line breaks that could matter are kept, which costs a few bytes and avoids a class of bug that is very hard to find later.

Are template literals safe to minify?

They are in this tool, because their contents are copied verbatim. Whitespace inside a template is part of the string value, so a minifier that collapses it silently changes what your program prints.

How does it tell a regex from a division sign?

By the preceding token. After a value, a variable or a closing bracket, a slash is division; after an operator, an opening bracket or a keyword like return, it starts a regular expression. That is the same rule the language itself uses.

Should I remove comments when minifying?

For production, yes — they are pure weight. Keep them if you are minifying to compare two files, since comments are often the only thing distinguishing two builds of the same source.

Can this replace a bundler?

No. A real build tool renames variables, removes unreachable code, splits bundles and generates source maps. This is for a quick tidy of a snippet, a config file or a script you are pasting somewhere.

Does it handle JSX or TypeScript?

The minifier will not corrupt them, since it only looks for string and comment boundaries. The beautifier is built for plain JavaScript, so JSX attributes and type annotations may not be reindented the way you expect.

Is my source code sent anywhere?

No. Both formatting and minification run as JavaScript in this page. Unreleased or proprietary code never leaves your machine.

Discover

Related developer tools