JS Minifier

Runs 100% in your browser

Minify JavaScript locally with token-aware protection for strings, templates, regex literals, comments, operators, and syntax-sensitive line breaks. Compare bytes, copy, and download privately.

JAVASCRIPT INPUT

Source code

0 bytes
0 lines 0 comments
MINIFIED JAVASCRIPT

Compact output

Waiting
0 bytes 0 lines
MINIFICATION REVIEW

Safety and savings

0 protected tokens
Load or paste JavaScript to see safe transformations, protected syntax, and warnings.
Input bytes0
Output bytes0
Saved bytes0
Reduction0%
Lines saved0
Comments0
Warnings0
HISTORY

Session history

  • No history yet.
Minification, not obfuscation. This tool does not rename variables, encrypt source, compile TypeScript or JSX, run code, mangle identifiers, or generate source maps. Test minified output with your project's parser, linter, and build pipeline before shipping to production.
Runs 100% in your browser — no JavaScript is uploaded, stored, or transmitted. Processing uses only in-page memory and disappears when you close or reload the tab.

Frequently asked questions

A JavaScript minifier reduces source size by removing comments and nonessential whitespace while preserving executable behavior. A lightweight minifier should protect strings, template literals, regular-expression literals, operators, and syntax-sensitive line breaks rather than relying on unsafe regular expressions.

Paste JavaScript into the source panel or open a local `.js`, `.mjs`, or `.cjs` file. Choose Safe minify or Review compression mode, inspect the protected-token and byte-savings summary, then copy or download the local `minified.js` result.

The dedicated first-phase tool uses a browser-local token-aware scanner to protect important JavaScript lexical forms. It is intentionally lighter than a full Terser, UglifyJS, or Closure Compiler AST optimizer and explains that limitation on the page.

Yes. Single-quoted and double-quoted strings are protected so spaces, comment-like text, punctuation, escapes, and URLs inside them are not deleted as source formatting.

Yes. Backtick template literals are treated as protected tokens, including embedded text and `${...}` sections. Review complex nested expressions and project syntax because a lightweight scanner is not a complete ECMAScript parser.

Yes. The scanner recognizes likely regular-expression literals separately from division operators and protects character classes, escaped slashes, and flags. Unusual syntax can produce a warning for manual review.

Yes. Ordinary line and block comments can be removed. A Preserve `@license`/`@preserve` option keeps common license and attribution comments rather than discarding them automatically.

The minifier removes whitespace around safe punctuation while retaining necessary boundaries between identifiers, operators, unary expressions, divisions, and other tokens. Review unusual operator-heavy code and run your normal build checks.

The tool preserves a space after line-sensitive keywords such as `return`, `throw`, `break`, `continue`, `yield`, and `await` where a following token could change the parse. Always run a linter or parser for production code.

No. Safe minification does not rename variables, function parameters, properties, or class names. Identifier mangling is a semantic transformation that belongs to a full parser-backed optimizer and can affect external APIs and debugging.

No. Minification reduces formatting overhead; it does not encrypt code, hide logic, rename identifiers, transform control flow, or provide reliable source protection. Use a separate parser-backed obfuscation workflow when that is the actual requirement.

Safe mode does not claim to perform semantic optimization. Review compression mode applies only limited, explicitly described cleanup and still does not provide the full compression guarantees of Terser, UglifyJS, or Closure Compiler.

The scanner handles common JavaScript source forms but is not a complete version-specific ECMAScript parser. Test import/export, optional chaining, nullish operators, decorators, TypeScript syntax, JSX, shebangs, and future syntax in your project toolchain.

The tool is intended for JavaScript source, not a complete JSX or TypeScript compiler. JSX angle brackets, type annotations, decorators, and framework-specific template syntax should be processed by the appropriate project compiler or parser.

Yes. The workspace reports input bytes, output bytes, reduction percentage, input/output lines, removed comments, protected tokens, and warnings so you can review the result instead of guessing.

Yes. Copy JS sends the result to the clipboard, and Download `.js` saves a local `minified.js` file. The dedicated browser client does not upload the source.

Yes. Open a local `.js`, `.mjs`, or `.cjs` file and process it in browser memory. The client does not use fetch, XHR, beacons, localStorage, or sessionStorage.

Minification primarily reduces transfer size and can reduce parsing or download overhead. Actual runtime performance depends on the application, browser, caching, compression, bundling, and code-splitting strategy.

A minifier removes unnecessary formatting for delivery, while a beautifier adds whitespace and indentation for readability. ToolsSonic treats these as separate workflows with different search intent and different safety goals.

Terser and UglifyJS are parser-backed development/build tools that can compress, mangle, generate source maps, and apply semantic transforms. This browser utility focuses on transparent local minification and explains that it is not a replacement for a project-aware build pipeline.

Any source transformation can expose assumptions in unusual syntax, embedded templates, generated code, or vendor-specific constructs. Compare output, run a parser/linter, execute tests, preserve the original source, and use a full optimizer when your project requires semantic compression.

The page is designed as a free browser utility with no account required. It provides local paste/file processing, token-aware protection, diagnostics, savings statistics, copy, and download without sending source to a remote conversion service.

Reducing JavaScript payload size can lower Time to Interactive and Total Blocking Time, two metrics that contribute to Core Web Vitals and Lighthouse scores. Pair minification with HTTP compression (Gzip or Brotli), code splitting, and deferred loading for the greatest impact.

Minification removes source text (comments, whitespace, and optionally identifiers) before the file is stored or served. Gzip and Brotli are transport-layer algorithms that compress the byte stream during HTTP delivery. Both are complementary: minification reduces the raw source size, and HTTP compression reduces the transferred bytes further.

What is JS Minifier?

A JavaScript Minifier reduces source size by removing ordinary comments and nonessential whitespace while protecting strings, template literals, regular-expression literals, operators, and syntax-sensitive line breaks.

Unlike unsafe tools that run global regex substitutions over source text, a correct JavaScript minifier must first extract and protect quoted strings, backtick template literals, regex literals, and comment bodies before touching whitespace — otherwise string contents, regex character classes, and operator sequences are silently corrupted.

Token-Aware Protection: Strings, Templates, and Regex

ToolsSonic's browser-only JS Minifier implements a multi-pass token scanner. In the first pass it extracts all string literals (single-quoted, double-quoted), template literals (backtick strings including "${...}" expressions), and regex literals (distinguished from division operators by tracking the regexAllowed context) into numbered placeholder slots. Block comments and line comments are detected and either removed or preserved depending on the @license/@preserve setting. On exit, every placeholder is restored from its slot.

The result is that contents of strings — including URLs, regular expressions embedded in strings, and template expressions — are completely invisible to the whitespace-removal and operator-boundary passes.

Safe Mode vs Review Compression Mode

Safe mode performs three transparent operations: comment removal (with optional license-comment preservation), structural whitespace collapse around JavaScript punctuation ({};,()[]=>), and keyword-boundary preservation for ASI-sensitive keywords (return, throw, break, continue, yield, await). These transformations preserve the observable behavior of well-formed JavaScript.

Review compression mode adds two reviewable operations: removal of redundant semicolons before closing braces (e.g., "};" collapsed), and collapsing of multiple blank lines. Review mode output should always be tested — the tool explicitly displays a review warning when this mode is active.

What This Tool Is Not

This is a lightweight formatting-removal tool, not a full optimizer. It does not rename variables, mangle identifiers, perform dead-code elimination, apply constant folding, generate source maps, or provide the same compression ratio as Terser, UglifyJS, or Google Closure Compiler. For production pipelines that require semantic compression, use a project-aware build tool. This browser utility covers the common case: removing comments and whitespace from a local .js, .mjs, or .cjs file privately and instantly, with full visibility into what was protected and what was changed.

Common use cases

  • Reducing JavaScript delivery size before deployment
  • Removing ordinary comments from a local JavaScript file
  • Minifying source containing strings, templates, and regex literals
  • Comparing input/output bytes and line savings
  • Preserving @license and @preserve comments
  • Reviewing safe minification separately from semantic compression
  • Minifying a private .js, .mjs, or .cjs file in the browser
  • Preparing a compact JavaScript draft before a project build

Why use ToolsSonic's JS Minifier?

The dedicated browser-only JS Minifier uses a token-aware scanner instead of unsafe regular-expression deletion. It protects quoted strings, template literals, likely regex literals, comments, operator boundaries, and line-sensitive keywords; offers Safe minify and Review compression modes; reports protected tokens, removed comments, and warnings; supports local files, copy, download, byte savings, and explicit boundaries around JSX, TypeScript, compilation, variable mangling, obfuscation, Terser, UglifyJS, and Closure Compiler.

JavaScript Minifier Protection Reference

Token typeProtected?Notes
Single-quoted strings ''✅ YesEntire content including embedded URLs and comment-like text extracted to slot
Double-quoted strings ""✅ YesSame as single-quoted; escape sequences honoured during scan
Template literals ``✅ YesBacktick string including ${...} expressions treated as one protected slot
Regex literals /pattern/flags✅ YesDetected via regexAllowed() context; character classes and escaped slashes preserved
Block comments /* */Removed / keptRemoved unless @license/@preserve is set; important comments kept when option enabled
Line comments //Removed / keptRemoved by default; shebang #! on line 1 preserved as a line comment
ASI keywords✅ Space keptreturn throw break continue yield await preserve trailing space before value token
Operator whitespaceCollapsedSpaces around { } ; , ( ) [ ] => removed; identifier boundaries kept

JS Minifier vs Terser vs UglifyJS vs Closure Compiler

FeatureToolsSonic JS MinifierTerser / UglifyJSClosure Compiler
Runs in browser✅ Yes — zero installNode.js / npm requiredJava / cloud API
Whitespace & comment removal✅ Token-aware✅ AST-based✅ AST-based
Variable mangling❌ No✅ Yes✅ Yes (advanced)
Dead-code elimination❌ No✅ Yes✅ Yes (advanced)
Constant folding❌ No✅ Yes✅ Yes
Source maps❌ No✅ Yes✅ Yes
Template literal protection✅ Yes✅ Yes (AST)✅ Yes (AST)
Private / no-upload✅ Browser-onlyLocal CLI onlyCloud API option
Best forQuick local review, private filesProduction bundlesAdvanced optimization
100% private — runs in your browser Instant — no server round-trip Free forever — no account needed

CSS Minifier

Editor's choice

Minify CSS locally with protected strings, URLs, data URLs, custom properties, calc expressions, safe color and zero-unit reductions, byte savings, diagnostics, history, copy, and download.

HTML Minifier

Editor's choice

Minify HTML locally by removing ordinary comments and unnecessary inter-tag whitespace while protecting pre, textarea, script, and style content. Compare byte savings, copy, and download the result privately.

HTML to JSX Converter

Editor's choice

Convert HTML to JSX online with React property mappings, inline style objects, defaultValue, TypeScript support, fragment wrapping, event handlers, boolean props, entities, and download — all private, no upload.

HTML Editor

Editor's choice

Edit HTML with a live preview — synchronized source editor, WYSIWYG visual pane, sandboxed preview, 5 starter templates, format, minify, validate, find/replace, file import, and download. 100% in your browser.

JSON Formatter

Editor's choice

Format, beautify, minify, and validate JSON locally. Choose indentation, sort keys, preserve Unicode, inspect statistics, and copy or download clean output.

JSON Validator

Editor's choice

Validate JSON online with precise line and column diagnostics, targeted repair hints, structure inspection, and browser-only processing — no upload, no account.