JS Minifier Online Free | Compress JavaScript Code Instantly

⚙️ Developer Tools Free Forever

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.

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 /**!, 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 last meaningful character before it was one of = ( , ! & | ? : ; { } 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.
Step 4 Whitespace collapsing Runs of spaces, tabs, and newlines are dropped completely except when the character before and after both look like they could be part of an identifier, keyword, or literal, in which case exactly one space is kept so two tokens do not merge into one.
// 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. This tool does none of that. It only removes comments and non-essential whitespace through a character scan, so the size reduction you see is honest but modest compared to a full AST-based minifier. 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, 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.

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.

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.

Privacy Overview

Cookies let this site remember your preferences and show us which tools people actually use. Full detail sits in our Privacy Policy.