Toolvist

JavaScript Minifier

Minify JavaScript online to shrink JS files and cut page weight with zero build step. Free JS compressor for faster script delivery.

Free Online JavaScript Minifier

The JavaScript Minifier strips comments and unnecessary whitespace from your JS to reduce file size. It is a dependency-free, string- and regex-aware minifier suitable for everyday code.

The result is worth sanity-checking with the JavaScript Obfuscator, which is the aggressive end of the same idea, and its structure can be reviewed with the JavaScript Minifier run in the opposite direction. For the stylesheet alongside it, the CSS Minifier is the counterpart.

How to use the JS Minifier

  1. 1 Paste your JavaScript, or load a file.
  2. 2 Choose whether to strip only whitespace and comments, or to also rename local variables.
  3. 3 Check the reported saving and any warnings.
  4. 4 Test the output. Minification can change behaviour if the code relied on variable names.

What the transform does

A minifier parses the source into a syntax tree, then re-emits it with the minimum characters that produce an equivalent tree. Whitespace vanishes, comments vanish, and where mangling is enabled, scopes are analysed so that local names can be shortened without collisions.

The requirement for correctness is that the analysis be sound. Renaming a variable that is referenced from a scope the analysis did not consider — through `eval`, or through a string that names it — produces code that is shorter and wrong. That is why directives which opt out of static analysis are the dangerous ones.

  • Whitespace and comment removal is always safe.
  • Mangling requires correct scope analysis to be safe.
  • `eval` and dynamic property access defeat static analysis.
  • Keep a source map if you minify for production debugging.

A Note on Scope

This is a lightweight, browser-based minifier. For production builds with full optimization (dead-code elimination, mangling), use a dedicated bundler like esbuild or Terser.

Frequently asked questions

What is the difference between minifying and mangling?

Minifying removes whitespace and comments, which never changes behaviour. Mangling renames local variables and function parameters to short identifiers, which reduces size further but requires analysing scopes correctly. Mangling is where most breakage happens, and it is also where most of the size saving comes from.

Why did my code stop working after minifying?

The most common cause is reliance on a function's declared name or argument count. Code that calls `toString()` on a function to inspect its name, or uses `arguments.length`, behaves differently once names are changed. So does anything using `eval`, which cannot be analysed statically and therefore cannot be mangled safely.

Should I minify my own build output?

Use a proper bundler instead. Minification is one step in a pipeline that should also resolve modules, tree-shake unused exports and handle the target environment. A standalone minifier is useful for checking what a piece of code costs, or for a single script that has no build step.

Related Developer Tools

Browse all Developer Tools →