Paritian

Developers

JavaScript Minifier

Removes comments and spare whitespace from JavaScript, conservatively.

Results

Minified function soma(a,b){return a+b;}var re=/a b/g;
Size before 96 B
Size after 45 B
Bytes saved 51 B
Share saved 53.13 %

What this tool does

This is a whitespace and comment stripper, not a compiler. It reads the code character by character and keeps track of whether it is inside a string, a template literal, a regular expression or a comment, which is what stops a naive minifier from destroying a regex that contains a slash or a string that contains two spaces on purpose. It does not rename anything and does not remove braces, so the output is your code with the same structure, just shorter.

Formula

strips comments and whitespace, while knowing about strings, template strings and regular expressions

Variables

SymbolMeaningUnit
textJavaScript
OUTMinified
SBSize beforeB
SASize afterB
SVBytes savedB
SPShare saved%

Worked example

  • JavaScript// soma dois números function soma( a , b ) { return a + b; /* simples */ } var re = /a b/g;
  • Minifiedfunction soma(a,b){return a+b;}var re=/a b/g;
  • Size before96 B
  • Size after45 B
  • Bytes saved51 B
  • Share saved53.13 %

Limitations

  • The calculation runs entirely in your browser. The values you type are never sent to a server.
  • For work that must comply with a standard or be signed off, check the result against the applicable code and have it reviewed by a qualified engineer.

Frequently asked questions

How does this compare with a real minifier?

It does far less, on purpose. A proper minifier parses the language into a syntax tree and can then rename local variables, drop unreachable branches, inline constants and remove braces — typically halving the file. Doing that safely requires the parser. This one only removes comments and whitespace, which it can do without understanding the code, and it explicitly knows about strings, template strings and regular expression literals so it does not damage them. For a build pipeline use a real minifier; for tidying a snippet this is enough.