JS Minifier — strip comments and whitespace
Paste a JavaScript file and get a minified version with comments and redundant whitespace removed. Strings, regexes and template literals are preserved verbatim.
Paste a JavaScript file and get a minified version with comments and redundant whitespace removed. Strings, regexes and template literals are preserved verbatim.
function greet(name){if(!name){return"Hello,stranger!";}return"Hello,"+name+"!";}const users=["Alice","Bob","Charlie"];users.forEach(function(u){console.log(greet(u));});This is a lightweight minifier — comments stripped, whitespace collapsed. For aggressive optimisation (renaming, dead-code elimination), use Terser or esbuild in your build pipeline.
It runs a single character-by-character pass over your JavaScript, removing line and block comments, collapsing whitespace runs to a single space (or zero where safe), and stripping spaces around punctuation. String literals (single, double, template), regular expression literals and license comments (/*! ... */) are preserved exactly as written.
This is a lightweight minifier, not a full optimiser. Tools like Terser, esbuild's --minify and SWC also rename variables, eliminate dead code, fold constants and shorten expressions — gains we don't aim for here. Use this when you need a quick, reliable byte reduction without setting up a build chain; reach for Terser when shipping production bundles.
For modern hand-written JavaScript, yes — strings, regexes and template literals are preserved exactly. As with any minifier, run your tests against the minified output before deploying. Rare edge cases (semicolon-insertion-sensitive code, IIFE comma operators) can be sensitive to whitespace removal.
Yes. The minifier doesn't parse the AST, it works at the lexical level, so any valid JavaScript syntax — class fields, optional chaining, top-level await, decorators — passes through unchanged.
This tool does not emit source maps. If you need to debug minified JS in production, generate maps with esbuild --sourcemap, Terser, or your bundler instead.
Strip types first (tsc, esbuild, swc) to get plain JS, then minify. Pasting TypeScript directly will technically work — comments and whitespace get stripped — but the output keeps the type annotations as syntax errors.
Pre-formatted code (Prettier, your editor's default) leaves less whitespace to remove. Minimal comments mean less to strip. The biggest savings come from heavily-commented hand-written modules or ESM-style code with deliberate spacing for readability.
Where stripping JS bytes pays off in seconds.
Small <script> blocks (analytics snippets, feature flags, user-message banners) get smaller and parse faster after minification — every byte saved is delivered on every visit.
Bookmarklets ship as single-line javascript: URLs with a ~2000-char limit in some browsers. Minify your draft to fit the limit while keeping a readable source separately.
Some legacy email systems allow JS in templates. Inlined and minified scripts there win twice — bytes and parser cost.
When pasting a code snippet that's also functional (a Stack Overflow style demo), minify it after you copy the readable version so the page itself stays light.
Habits that keep JS lean from authoring through deployment.
Terser and esbuild --minify do everything this tool does plus dead-code elimination, identifier renaming, and constant folding — typically 2-3× more savings on real codebases.
Author with comments and whitespace; minify on deploy. Editing minified code by hand introduces subtle bugs that don't show up until production.
Code like 'a = b\n[1, 2, 3].forEach(...)' relies on automatic semicolon insertion. Removing the newline can change semantics. If your code uses ASI heavily, prefer Terser which understands the parser rules.
If your build chain includes Babel or SWC, run minification after transpilation. Minifying first-then-transpiling can produce bloated output because the transpiler may re-add whitespace.