What JS Minification Does
JavaScript minification strips characters from source code that exist purely for human readability — comments, indentation, and unnecessary whitespace — without changing what the code actually does when it runs. A JavaScript engine doesn't care about formatting; it only needs valid tokens in the right order. Removing that formatting reduces file size, which speeds up download time and, for scripts that block rendering or run before the page is interactive, can measurably improve page load performance. Minification is standard practice in production front-end builds and is usually handled by a bundler like Webpack, esbuild, or Terser as part of the build pipeline, but this tool is useful for quickly minifying a standalone script, a bookmarklet, or an embed snippet that doesn't go through a formal build step.
How This Minifier Works — and Why It's Whitespace-Only
Paste JavaScript into the left panel and click Minify JS. With Remove Comments enabled, both `//` line comments and `/* ... */` block comments are stripped. With Collapse Whitespace enabled, runs of spaces, tabs, and blank lines are reduced to the minimum needed to keep the code valid. This tool deliberately does not rename variables, remove dead code, or restructure logic the way a full production minifier like Terser or UglifyJS does — those transformations require parsing JavaScript into a full abstract syntax tree to understand scope, closures, and control flow, and a mistake there can silently change behavior rather than just size. This tool sticks to changes that are unambiguously safe: comments and formatting whitespace that the JavaScript engine ignores entirely.
Why Strings, Template Literals, and Regex Need Special Care
The single riskiest part of writing a JavaScript minifier by regex is that the characters `//` and `/* */` don't always mean "comment." A regular expression literal like `/\/\*not-a-comment\*\//` contains `/*` and `*/` sequences that must not be treated as a block comment, and a string like `"http://example.com"` contains `//` that must not be treated as a line comment. Template literals (backtick strings) can also span multiple lines by design, and collapsing whitespace inside one would change the actual string value your code produces at runtime. This tool scans for string, template-literal, and regex-literal boundaries first and protects their contents before touching comments or whitespace, then restores them exactly afterward, so URLs, regex patterns, and multi-line template strings are never corrupted by the minification pass.
Automatic Semicolon Insertion: A Silent Minifier Trap
JavaScript has a feature called Automatic Semicolon Insertion (ASI) that lets you omit semicolons in many places, with the engine inferring where statements end based on line breaks. This becomes dangerous during whitespace collapsing: naively joining two lines that each relied on ASI can merge two separate statements into one with a different meaning — the classic example is a line ending in `return` followed by a value on the next line, where ASI silently turns it into `return;` (returning undefined) even though the original code intended to return the following expression. This tool avoids that class of bug by never merging lines across statement boundaries in a way that could change how ASI applies, keeping the collapsing strictly to redundant whitespace rather than restructuring line breaks that carry meaning.
Minification vs. Uglification vs. Obfuscation
These three terms get used interchangeably but describe different levels of transformation. Minification, what this tool does, removes only formatting that has zero effect on execution. Uglification goes further, typically renaming local variables to short single-letter names and removing genuinely dead code branches — still behavior-preserving, but requiring a real parser to do safely. Obfuscation goes further still, deliberately restructuring control flow, encoding strings, and inserting misdirection specifically to make code hard for a human to read even after formatting it back out, usually for the purpose of protecting intellectual property or hindering reverse engineering rather than reducing file size. For most production web apps, a build-tool-integrated minifier/uglifier like Terser (bundled into Webpack, Vite, and esbuild by default) is the right long-term choice; this tool is best suited for quick, one-off minification outside a build pipeline.
Best Practices for Shipping Minified JavaScript
Always keep the original, readable source in version control and treat minified output as a disposable build artifact, never the source of truth. Pair minification with source maps in your actual build pipeline so that errors reported in production still point back to readable line numbers during debugging — something a standalone tool like this one can't generate, since it doesn't track a mapping back to the original positions. Combine minification with gzip or Brotli compression at the server or CDN level; the two are complementary, since compression works even better on text with reduced redundant whitespace. For anything beyond a quick standalone script or embed snippet, wire minification into your bundler so it happens consistently on every build rather than as a manual, easy-to-forget step.
Frequently Asked Questions
Will minifying change how my JavaScript behaves?
No. Only comments and formatting whitespace that the JavaScript engine ignores are removed. This tool doesn't rename variables, delete code, or restructure logic, so execution should be identical before and after minification. Always test minified output before deploying it, as with any build step.
Why didn't the whitespace inside my string get touched?
String contents, template literals, and regex literals are detected and protected before any comment removal or whitespace collapsing happens, since characters like `//` or `/*` inside them don't mean "comment" and stripping whitespace inside a template literal would change the actual string value.
Does this tool rename my variables to save more space?
No. Variable renaming (part of what's often called "uglification") requires understanding scope and closures via a full parser to do safely, since renaming the wrong variable can break code that relies on a specific name via `eval`, dynamic property access, or a global. This tool only removes comments and redundant whitespace, both of which are always safe to remove.
Is this a replacement for Terser or my bundler's minifier?
Not for production builds. Bundler-integrated minifiers parse a full AST and can safely rename variables, remove dead code, and generate source maps for debugging. This tool is meant for quick, one-off minification of a standalone script, bookmarklet, or embed snippet outside a formal build pipeline.
Is my code uploaded anywhere when I use this tool?
No. Minification runs entirely in your browser using JavaScript. Your source code is never sent to or stored on a server, which makes this safe for unpublished, private, or proprietary code.