← Back to DevKit

JavaScript Minifier

JS MINIFY · CODE FORMAT

Conservative JS minification: strips comments, indentation and blank lines while preserving strings and regexes verbatim — no renaming, still runs.

JAVASCRIPT input
Minified output · conservative mode
Conservative mode: only strips comments, leading indentation and trailing whitespace, drops empty lines and merges consecutive ones; no variable renaming / AST rewriting / cross-line joining. Strings, template literals and regex literals are preserved verbatim. /*! and comments containing @license / @ are kept.

>_ USAGE GUIDE

A conservative-mode JavaScript minifier: it strips comments, indentation, and blank lines, cutting file size immediately. The design principle is "never change behavior" — strings and regex literals are preserved verbatim, variables are not renamed, statements are not reordered — so the output behaves exactly like the input and can be pasted straight back into your project.

  1. Paste the source: any JavaScript snippet or script file
  2. Minify: comments and whitespace disappear; code semantics do not
  3. Copy the compact output: ready for delivery or embedding

Good fits: slimming a single-page script handed to a client, quickly compressing a utility snippet, and handling one-off scripts without setting up a build. Size savings depend on comment density: heavily documented internal scripts often shrink 30% or more, while already-terse code gains little — either way, behavior is untouched, which is the whole point of conservative mode. Compression runs locally in the browser — source code is never uploaded.

>_ FAQ

Q1 · What is the difference between minification and obfuscation?

Minification performs equivalence-preserving transformations: remove whitespace and comments to reduce size, leaving semantics untouched and reversing trivially. Obfuscation deliberately reshapes the code — renaming variables, encrypting strings, scrambling control flow — to raise the cost of reverse engineering, sometimes even growing the file. This tool does conservative minification only.

Q2 · Why not rename variables — wouldn't that compress more?

Renaming (userName to a) saves more but needs full syntactic analysis to be safe; done carelessly it breaks scopes, eval references, and exported symbols. This tool's contract is "conservative and reliable" — any input produces output that still works. For maximum compression use a build-chain tool (Terser, esbuild), which has a complete parser.

Q3 · How do I verify the minified code still works?

Conservative mode guarantees "only removed, never changed", but the prudent routine still applies: compare file sizes before and after (a 20–40% reduction is typical); run a smoke test over the key features; execute the unit tests if they exist. Minification is a routine release step and verification is cheap.

Q4 · Will spaces or comments inside strings be deleted?

No. String and regex literals are preserved byte for byte — the space in "hello world" survives, and a // inside a string is never mistaken for a comment. This is precisely where parse-free minifiers fail, and the tool applies lexical-level handling to guarantee it.

Q5 · What should a real production project use to minify JS?

The build toolchain is the answer: esbuild for speed, Terser for deep optimization, or the built-in pipelines of Vite and Webpack. They perform syntax-level minification — variable renaming, dead-code elimination, constant folding — far beyond conservative mode. This tool's niche is buildless scenarios: single-file scripts, quick manual passes, and ad-hoc needs.

Embed code

Paste the code below into your page to embed this tool as an iframe (nav and footer auto-hidden).

Heightpx
This tool runs entirely in your browser — input never leaves your device. Press Ctrl K to switch tools anytime.