JS Minifier
A conservative, browser-only JavaScript minifier. Strips // and /* */ comments (string- and regex-aware), collapses whitespace, drops blank lines, and joins lines where ASI safety allows. No variable renaming, no dead-code elimination — for production, reach for Terser or esbuild.
How to use
- 1
Paste your JavaScript
Drop a script — a utility function, a small module, a code snippet — into the left-hand editor. Comments, indentation and blank lines are fine.
- 2
Toggle comment stripping
By default // and /* */ comments are removed (string- and regex-aware so they don't get stripped inside literals). Turn the switch on to keep them.
- 3
Minify and review
Click Minify JS. Whitespace is collapsed, blank lines dropped, and consecutive lines are joined where ASI (automatic semicolon insertion) safety allows. The before/after sizes and savings % update instantly.
- 4
Copy or download
Copy the minified output to your clipboard, or download it as app.min.js.
Common use cases
- Strip comments and indentation from a small JS utility before pasting into a CMS or inline <script>.
- Quickly see how much of a file is whitespace and comments vs. real code.
- Pre-minify a snippet before shipping it as a bookmarklet or browser extension content script.
- Teach the difference between conservative minification (this) and full minification (Terser).
Limitations
- Conservative only. No variable renaming, no dead-code elimination, no property mangling, no ES module conversion. Expect 10–30% savings vs. 40–70% for Terser/esbuild.
- Template literals with
${...}expressions containing comments or regexes are not deeply analysed — the walker treats the whole template as a single string. Avoid this minifier for code with side-effects inside template interpolations. - Regex detection is heuristic: a
/after(,,,=,:,[,!,&,|,?,{,;,+,-,*,%,~,^,<,>, or the keywordsreturn,typeof,instanceof,in,of,new,delete,void,throw,else,case,do,await,yield,if,while,for,switch,catchis treated as a regex start. - Inputs larger than 1 MB are rejected to keep the tab responsive.
- JSX and TypeScript syntax are not specially handled — type annotations and JSX tags may be mangled. Strip them with
tscoresbuildfirst.