Minify JavaScript

Minify JavaScript layout while preserving strings, regexes, and token boundaries.

freeworks offlinenothing uploaded
ToolJavaScript Minifier
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

Comments and nonessential whitespace are removed while quoted values, templates, regex literals, and required separators remain. This is lexical minification, not dead-code elimination or name mangling.

  • A syntax-preserving pass is suitable for a quick preview.
  • AST-aware build tools handle deeper compression.

Worked example

Minify JavaScript
Remove whitespace and comments from JavaScript code
Input
											// Utility function
function add(a, b) {
  return a + b;
}

const result = add(2, 3);
										
Output
												function add(a,b){return a+b;}const result=add(2,3);
											

When to use this

Transfer-size estimates, bookmarklets, and pre-bundle reviews minify JavaScript.

Edge cases

  • A newline after return can affect automatic semicolon insertion.
  • A slash may begin a regex or mean division.
  • Joining identifiers changes their token.

References