Free Converter

JavaScript Minifier

Minify and compress JavaScript code instantly in your browser. Remove comments, collapse whitespace, and reduce file size. Free and private.

Drag & Drop a JS file here

Supports .js files. Or paste your JavaScript above.

Or

About JavaScript Minification

JavaScript minification reduces the size of source code by removing unnecessary characters and (with proper minifiers) renaming local variables to shorter names. The first category — whitespace and comment removal — is straightforward and risk-free. The second — variable renaming — requires understanding scope rules and is what production minifiers like Terser and esbuild do best.

This tool focuses on safe minification: stripping comments, collapsing whitespace, removing redundant semicolons, and shortening obvious patterns. Variable renaming is conservative — only local variables in clear scopes are touched, and externally-referenced names are left alone. The result is functionally identical to the source.

For production-grade minification, dedicated tools (Terser, esbuild, swc) understand the full ECMAScript scope model and produce significantly smaller output. This tool is for quick browser-side minification when a full build setup is not available.

Why Minify JavaScript

JavaScript bundles are typically the largest single resource on a modern webpage. Minification routinely produces 30–60% size reduction versus the unminified source. Combined with gzip or Brotli, the reduction shrinks somewhat, but the combination still saves measurable bytes — particularly for users on slow connections.

Faster JavaScript also means faster Time to Interactive. Smaller scripts download faster, parse faster, and execute sooner. For sites where TTI affects bounce rates and SEO ranking, minification is one of the cheapest wins available.

How to Minify JavaScript

Paste JavaScript, get a smaller version.

  1. Add JavaScript input: Paste source into the input area or drop a .js file. The minifier accepts modern JavaScript (ES2015+) including arrow functions, template literals, classes, and modules.
  2. Choose options: Defaults strip comments and collapse whitespace. Local variable renaming is conservative; enable more aggressive renaming if you need maximum compression.
  3. Minify: The minifier parses the source, removes whitespace and comments, and emits compact output. Syntax errors in the source produce clear error messages.
  4. Use the output: Replace your script source in production. For full optimization, pair with a bundler that handles tree-shaking and dead code elimination.

Common Use Cases

Technical Details

The minifier tokenizes JavaScript using a parser that respects ECMAScript syntax. Comments (single-line and multi-line) are removed except for license comments marked with /*! prefix. Whitespace is collapsed except where syntactically required (between identifiers, after keywords).

Conservative variable renaming shortens local variables in straightforward scopes. Globals, exports, and imported names are not renamed — that would break external references. For deep renaming, use Terser or esbuild with proper module-aware analysis.

Edge cases: automatic semicolon insertion (ASI) means the minifier must preserve newlines in some contexts to avoid changing program behavior. Template literals, regex literals, and JSX (if input includes it) are preserved exactly because their contents may not be safe to compress.

Best Practices

Frequently Asked Questions

Is this as effective as Terser or esbuild?
No. Production minifiers like Terser, esbuild, and swc apply more aggressive transformations including dead code elimination, scope-aware renaming, and constant folding. This tool offers basic minification for ad-hoc use.
Will minification break my code?
Properly applied, no. Edge cases involve unusual ASI behavior and code that depends on function name strings (Function.prototype.name). Test minified output against your test suite.
Are modern ES features supported?
Yes. Arrow functions, template literals, classes, async/await, destructuring, and other ES2015+ features pass through correctly.
Will variables be renamed?
Conservatively. Local variables in clear scopes are renamed to shorter names; globals, exports, and imports are preserved.
Is my code uploaded to a server?
No. The minifier runs in your browser.
How much smaller will my JavaScript be?
Typically 30–60% reduction. Variable-heavy code with long identifiers compresses more; expression-heavy code compresses less.
Should I minify by hand?
Never. Maintain readable JavaScript in source. Run minification as a build step or as part of deployment.
Does it work on TypeScript?
TypeScript needs to be compiled to JavaScript first using tsc or esbuild. Once compiled, the resulting JavaScript can be minified.