JS Minifier – Compress & Minify JavaScript Online Free
Remove comments, whitespace, and dead code from JavaScript instantly. See exact byte savings. Upload a .js file or paste code directly. Optionally strip console.log statements for cleaner production output.
A single-pass character state machine for stripping JavaScript, without touching your logic
Minifying JavaScript safely is not about deleting whitespace with a regex. The danger is that comments, strings, template literals, and regex literals can all contain characters that look like code but are not. Strip whitespace blindly and you will mangle a string like "function () { }" or break a regex like /\s+\d/. This tool avoids that by scanning the source one character at a time and tracking exactly what kind of token it is currently inside.
The whole process runs client side. There is no server call in the script, so your source code never leaves the browser tab it was pasted into.
The state machine, token by token
A single index pointer walks the input string. At each position the minifier checks, in order, whether it has landed on a line comment, a block comment, a template literal, a single or double quoted string, or a regex literal. Only if none of those match does it fall through to generic whitespace and token handling.
*/. Both are dropped entirely unless they start with //!, //*, /*! or /**!, in which case the banner-preserving option keeps the first one found, which is the common convention for license headers.
${ } expression boundaries with a nested brace counter, since an interpolated expression can itself contain braces.
= ( , ! & | ? : ; { } or a newline, or if it is the very first token. That heuristic distinguishes a / b division from a /pattern/ literal without a full parser.
What gets removed and what survives
| Removed | Preserved |
|---|---|
| Line and block comments | Banner comments starting with //! or /*!, if the option is checked |
| Redundant whitespace and newlines | String contents, including embedded whitespace, exactly as written |
| Duplicate semicolons | Regex literal bodies and their flags, character by character |
| console.log/warn/error/info/debug/trace calls | All variable and function names, since this tool does not rename identifiers |
| Trailing semicolon before a closing brace | Template literal interpolation expressions, braces tracked recursively |
Two options worth understanding
Keep console statements
Unchecked, a final regex pass removes any console.log(...), console.warn(...), and similar calls including their arguments, using a non-greedy match up to the next closing parenthesis. Multi-line console calls with nested parentheses in their arguments can confuse this pass, so review the output if your calls are unusually complex.
Keep banner comment
Only the first matching banner comment in the file is preserved, tracked with a boolean flag so a second license-style comment further down does not also survive. This mirrors how most minifiers handle license headers, keeping exactly one at the top of the output.
The compression stats bar reports original size, minified size, and percentage saved. Byte counts come from TextEncoder().encode(...).length, which measures actual UTF-8 bytes rather than JavaScript string length, so the percentage reflects real transfer size savings, not character count.
Minifiers and bundlers
- Terser is the AST-based minifier that most modern bundlers use under the hood, with full variable renaming and dead code elimination.
- UglifyJS is the older ES5-focused minifier Terser was forked from.
- ECMA-262, the ECMAScript Language Specification defines the tokenization rules, including the exact regex-versus-division ambiguity this tool resolves heuristically.
- MDN, TextEncoder covers the API used for the byte-accurate size comparison.
Where the bytes matter
Quickly shrinking a standalone script tag before pasting it into a CMS with a character limit, stripping debug console calls out of a script before sharing it, tidying a vendor snippet that shipped with excessive comments, and getting a rough before and after size comparison without wiring up a full bundler for a one off file.
Questions About the JS Minifier
JavaScript minification removes all characters from a script that are not needed for it to execute correctly: comments, newlines, extra spaces, and sometimes semicolons. The result runs identically to the original but transfers faster over the network. Minification is a standard production build step for any web application that ships JavaScript.
No. This is a whitespace and comment stripper, not a full compiler. It does not mangle variable names, tree shake unused code, or inline constants. For full optimization in production, use Terser (via Webpack or Vite), esbuild, or the Closure Compiler. This tool is ideal for quick one off minification, legacy scripts, or small projects without a build pipeline.
Not if your code is syntactically correct and doesn’t depend on automatic semicolon insertion in non standard ways. The minifier preserves all string and regex literals exactly. Always test minified output in your target browsers before deploying. If you have issues, the most common cause is code that was already relying on implicit newline as semicolon behavior in an edge case.
Console statements left in production code can expose internal data structures, variable names, API responses, and debugging information to anyone with browser DevTools open. They also add a small performance cost since the browser has to evaluate the arguments even if DevTools is closed. Removing them is a standard production hygiene practice. Enable the option in this tool to strip them automatically.
Whitespace and comment removal typically reduces file size by 10 to 30 percent on well commented code. Full minification with variable renaming (Terser) can reduce size by 30 to 60 percent. Combined with gzip or Brotli compression from the web server, the total reduction compared to the original file is typically 70 to 85 percent.
This tool works on plain JavaScript. TypeScript must be compiled to JavaScript first before minifying. ES module syntax (import/export) passes through correctly since this tool strips only comments and whitespace without parsing the module graph. Minify the compiled JavaScript output, not the TypeScript source.
No. All minification runs in your browser as JavaScript. Your source code never leaves your machine. This makes it safe to use with proprietary application code, internal APIs, or any code you would not want to transmit to a third party server.
Minification removes whitespace and comments to reduce file size while keeping the code readable to a developer who formats it. Obfuscation intentionally makes code hard to understand by renaming variables to meaningless names (a, b, x1), encoding strings, and inserting confusing control flow. Minification is for performance; obfuscation is for intellectual property protection. This tool does minification only.
From the blog
Deep dives on the things these tools touch
Minification, UUID collisions, diffing API responses, and the other questions that come up around this toolset.