How to use this JavaScript minifier
Paste your code into the top box and press “Minify JavaScript”. The tool first breaks the code into tokens — words, numbers, strings, regexes and punctuation — the same way an interpreter reads it. Only then does it decide what can be removed: comments are dropped, runs of whitespace collapse, and spaces around operators disappear where they carry no meaning. The result appears below with a character count and the percentage saved, ready to copy or download as a .js file.
Honesty about scope matters here. This is a basic minifier. It will not rename calculateTotalPrice to a, fold constants or drop dead code — those tricks need a real compiler such as Terser, and they belong in a build pipeline. What this page gives you is a safe, instant squeeze for snippets, embedded scripts, bookmarklets and one-off files, with output you can still read and recognise as your own code.
Example: a greeting function, before and after
This short function, with a comment at the top and another mid-line:
minifies to:
That is 230 characters down to 136 — 94 saved, 40.9% smaller. Both versions were actually run: greet("Bob") returns Hello, Bob! (letter o x 2) either way. Note the details the tokenizer got right: the /o+/g regex survived intact, the division-free code was never confused by slashes, and the spaces inside the string literals — which are part of the output text — were not touched.
Why JavaScript is harder to minify than it looks
Three features make naive whitespace removal dangerous. First, the slash: a / b is division, but /o+/g is a regular expression, and only the surrounding context tells you which. This tool decides from the previous token, the same heuristic real parsers start from. Second, strings: a // inside quotes is text, not a comment, so the tokenizer scans strings — including template literals with their nested ${ } expressions — before it removes anything. Third, automatic semicolon insertion: a newline after return genuinely ends the statement, so newlines are kept wherever removing one could change the program's meaning. A minifier that ignores any of these will eventually break someone's code; a basic one that respects all three stays trustworthy.
When to use this — and when to use a build tool
Reach for this page when the job is small and immediate: shrinking a snippet for a forum answer, preparing a bookmarklet, trimming a hand-written script for a static page, or checking how much of a file is pure commentary. Reach for Terser, esbuild or your bundler when the code ships as part of a product: they rename variables safely, remove dead code and handle entire module graphs. The two are not rivals. Most production sites use a build tool for their bundles and a quick online minifier for everything else — and knowing which is which is most of the craft.
What a basic minifier deliberately leaves behind
It is worth being precise about the gap between this tool and a compiler-grade minifier, because the gap is a list of deliberate choices. Variable renaming is left out because it requires scope analysis. Dead-code removal is left out because deciding what is dead requires understanding the whole program, including what other scripts might call. Constant folding and expression rewriting are left out because they change the code's shape, not just its spacing. Even semicolon removal — safe in most places — is left out, because the places where it is unsafe are exactly the ones a quick tool should not gamble on. What remains is the honest core of minification that predates all the cleverness: take out the comments written for humans and the whitespace laid out for humans, and give the browser the same program in fewer bytes. For a great deal of the JavaScript on the web — hand-written, single-file, unbundled — that core is most of the available saving anyway.
Frequently asked questions
Is this a full JavaScript minifier like Terser?
No — and it does not pretend to be. This is a basic minifier: it removes comments and unnecessary whitespace using a small tokenizer, but it never renames variables, never removes semicolons and never rewrites expressions. Build tools like Terser or esbuild shrink code further by renaming and restructuring; use one of those in a production build pipeline, and use this page for quick, safe, one-off jobs.
Will the minified code do exactly the same thing?
That is the design goal. The tokenizer understands string literals, template literals and regular expressions, so comment-like text inside a string is never touched, and a slash that means division is never confused with the start of a regex. Newlines that JavaScript itself treats as meaningful — after return, break or continue, for example — are kept. The sample on this page was run before and after minifying and produces identical output.
How much smaller will my JavaScript get?
Comment-heavy, generously spaced code commonly shrinks by 20–40% from whitespace and comment removal alone. The sample on this page drops from 230 to 136 characters — 40.9% smaller. Renaming variables would save more, but that is a build-tool job; this tool deliberately stays conservative.
Why not rename variables to single letters?
Renaming is where minifiers stop being simple text processors and become compilers: doing it safely requires understanding scope, closures, eval, and which names are public API. A mistake produces code that fails in ways that are painful to debug. Leaving names untouched keeps this tool predictable — the output is your code, just tighter.
Does it handle template literals and regexes?
Yes. Template literals are copied completely untouched, including everything inside ${ } expressions, because their whitespace can be part of the output text. Regular expressions are recognised by context — after operators, brackets and keywords such as return — and copied verbatim, while a slash between values is treated as division.
Are there any patterns it may not survive?
Honestly, a few rare ones. A regular expression written immediately after a closing brace is ambiguous even for parsers, and this tool reads it as division. Code that relies on source text — reading its own function source, for example — will also see different whitespace. For ordinary application code, snippets and bookmarklets, neither applies. When in doubt, test the minified output; it only takes a moment.
Is my code uploaded to a server?
No. Everything runs in JavaScript inside your own browser. Your code — including proprietary or work code — never leaves your device, and nothing is stored or logged.
Why does it keep some newlines?
Because JavaScript sometimes gives newlines meaning. A line break after return ends the statement (automatic semicolon insertion), and a break before ++ or before a bracket can change what the code does. Wherever a newline could matter, this minifier keeps one; everywhere else, lines are joined. Safety first, bytes second.
Can I download the minified JavaScript?
Yes. The Download button saves the result as a script.min.js file, and the Copy button puts it on your clipboard — both use the exact text shown in the result box.