CodeKitHub
English
Code Tools

JavaScript Minifier & Formatter

Paste JavaScript below to minify it — mangling variable names, removing whitespace and dead code — or beautify it into readable, indented code. Both directions parse your code into a real syntax tree instead of using text tricks, so regex literals, template strings and scoping are handled correctly.

What Is This Tool?

A JavaScript minifier rewrites code to be as small as possible while behaving identically: it shortens variable and function names where safe, removes comments and whitespace, folds constants, and eliminates unreachable code.

This tool is built on Terser, the AST-based minifier used by webpack, Vite, Rollup and most modern JavaScript build tools. Because it actually parses your code rather than pattern-matching text, it correctly distinguishes a division operator from a regex literal, doesn't break template strings that contain //-looking sequences, and won't rename a variable into a name that collides with something in an outer scope.

Why Use It?

  • AST-based minification (Terser), the same engine used by major bundlers — safe with regex literals, template strings and closures.
  • Mangles variable names for real size savings, not just whitespace removal.
  • See exactly how many bytes and what percentage you saved.
  • Format mode turns obfuscated, single-line minified JS back into readable, indented code — useful for understanding third-party scripts.
  • 100% local processing — proprietary code never leaves your browser.

How to Use

  1. Paste your JavaScript into the input box, or click "Load Example" to try a sample with a regex literal and a template string.
  2. Click "Minify" to compress it, or "Format" to beautify it with 2-space indentation.
  3. Check the message under the boxes — minify mode shows the size reduction; a syntax error in your code shows a clear message instead of silently producing broken output.
  4. Click "Copy" to grab the result.

Example

Input

function greet(name) {
  const pattern = /^[a-z]+$/i;
  const msg = `Hello, ${name}!`;
  if (pattern.test(name)) {
    // simple check
    return msg;
  }
  return "Hi there";
}

Output

function greet(n){const e=/^[a-z]+$/i,g=`Hello, ${n}!`;return e.test(n)?g:"Hi there"}

Variable names are shortened, the comment and the if-statement are collapsed into an expression, but the regex literal and template string are preserved exactly and the behavior is unchanged.

Practical tips

  • Minify at build time, not by hand-editing — keep readable source under version control and generate the minified bundle as a build step.
  • If minified output behaves unexpectedly, check for code relying on Function.prototype.name or reflection — mangling renames functions and that can surface in rare edge cases.
  • Formatting a third-party script before reading it is much faster than trying to parse a single 2,000-character line.
  • Combine with the HTML and CSS minifiers below if you're preparing a full static bundle for deployment.

Where this fits in real workflows

JavaScript is usually the largest render-blocking or parse-blocking asset on a page, so minifying it has a real, measurable effect on load time — more than HTML or CSS byte-for-byte. Most modern frameworks do this automatically at build time, but hand-written scripts, browser extensions, and bookmarklets often ship unminified unless someone runs them through a tool like this one.

The Format direction is commonly used the opposite way: debugging a production error from a minified stack trace is much easier once the surrounding code is reformatted and readable, even without the original variable names.

HTML Minifier · CSS Minifier

Common use cases

  • Shrinking a standalone script or bookmarklet before publishing it.
  • Reformatting a minified script pulled from a live site to understand what it does.
  • Cleaning up JavaScript pasted from a forum post or AI-generated snippet before reading it carefully.
  • Quickly checking whether a hand-written JS snippet has a syntax error, since a parse failure surfaces as an explicit message.

Frequently Asked Questions

Is my JavaScript uploaded anywhere?

No. Minification and formatting both happen locally in your browser using JavaScript. Nothing you paste is sent to a server, which makes it safe for proprietary or unreleased code.

Is minified JavaScript safe to ship — will it break my code?

It's built on Terser, an AST-based minifier trusted by webpack, Vite and Rollup for production builds, so it correctly parses JavaScript rather than guessing from text. That said, any minifier can occasionally interact badly with code that relies on function.name, eval(), or non-standard globals — test your bundle after minifying, as you would with any build tool.

Does minifying obfuscate my code?

It shrinks variable names and removes structure, which makes code harder to read, but this is not real obfuscation or protection — anyone can still run it through a formatter (like the Format button here) and read the logic. Don't rely on minification to hide secrets or business logic.

How much smaller does JavaScript typically get?

Hand-written code with long variable names, comments and whitespace commonly shrinks 50-70% through minification and mangling. Code already produced by a bundler will save less.

Can I read minified JavaScript from a website I'm inspecting?

Yes — paste it and click "Format" to reindent it. Variable names will still be short and meaningless since minification already discarded the originals, but the structure becomes readable.

Related Tools