⚙️ Developer Tools Free Forever

JS Minifier – Compress & Minify JavaScript Online Free

Remove comments and whitespace from JavaScript instantly, or switch on full minify to rename variables and drop dead code. See exact byte savings. Upload a .js file or paste code directly. Optionally strip console.log statements for cleaner production output.

Input JavaScript
Minified JavaScript
-
Original
-
Minified
-
Savings
Note: This tool removes comments and whitespace. It does not rename variables or perform advanced optimizations like Terser or Closure Compiler. For production use, consider integrating a build tool.
About This Tool

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.

Step 1 Comments Line comments run to the next newline. Block comments run to the next */. Both are dropped entirely unless they start with //! or /*!, or contain @license or @preserve, in which case the banner-preserving option keeps the first one found, which is the common convention for license headers.
Step 2 Strings and template literals Quoted strings are copied through untouched, including their internal whitespace, with backslash escapes consumed as a pair so an escaped quote does not end the string early. Template literals additionally track ${ } expression boundaries with a nested brace counter, since an interpolated expression can itself contain braces.
Step 3 Regex literal detection A forward slash only starts a regex if the token before it is an operator or opening bracket, a keyword such as return or typeof, or nothing at all. That heuristic distinguishes a / b division from a /pattern/ literal without a full parser.
Step 4 Whitespace collapsing Spaces and tabs are dropped unless two tokens would merge, like var x or a + +b. A newline is kept wherever it could end a statement, so code written without semicolons still runs exactly the same.
// simplified regex-literal detector from the actual minifier if (c === '/') { var prev = out.join('').replace(/\s+$/, ''); var lastChar = prev[prev.length - 1] || ''; var reContext = '=([,!&|?:;{}\n'.indexOf(lastChar) >= 0 || prev === ''; if (reContext) { /* consume as a regex literal, including [...] char classes */ } }

What gets removed and what survives

RemovedPreserved
Line and block commentsBanner comments starting with //! or /*!, if the option is checked
Redundant whitespace and newlinesString contents, including embedded whitespace, exactly as written
Duplicate semicolonsRegex literal bodies and their flags, character by character
console.log/warn/error/info/debug/trace callsAll variable and function names, since this tool does not rename identifiers
Trailing semicolon before a closing braceTemplate literal interpolation expressions, braces tracked recursively
This is a stripper, not a compressor. Real minifiers such as Terser or UglifyJS parse your code into an abstract syntax tree, then rename local variables to single letters, inline constants, and eliminate dead branches. The default safe mode does none of that. It only removes comments and non-essential whitespace through a token scan, so the size reduction is honest but modest. Tick Full minify to run Terser itself in your browser, with variable renaming and dead code removal. For a production build pipeline, use this as a quick client-side preview, not a replacement for your bundler's minification step.

Two options worth understanding

Keep console statements

Unchecked, calls such as console.log(...) and console.warn(...) are removed with their arguments. The tool matches the brackets token by token, so nested calls and multi-line arguments are handled. A console call used inside an expression is replaced with void 0 so the code around it stays valid.

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.

Character-level state machine Template literal aware Regex vs division disambiguation UTF-8 byte accurate stats

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.

Common Questions

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.

Only if you ask it to. The default safe mode strips whitespace and comments and leaves every name as written. Tick Full minify and the tool runs Terser in your browser, which shortens local variable names, removes dead code and compresses expressions. Global names and properties are never renamed. 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. Strings, template literals and regex literals are kept exactly, and safe mode keeps a newline wherever one could end a statement, so code without semicolons still works. If the input has a syntax error, the tool shows the line and column instead of producing broken output. Always test minified output before deploying.

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, and Full minify detects modules automatically. 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.