Frontend Tools
JS Minifier: Compress JavaScript Online
Minify JavaScript by removing comments and whitespace without breaking strings, regexes or template literals. Keeps licence comments and shows bytes saved.
How to use JS Minifier: Compress JavaScript Online
Paste JavaScript into the box and the minified code, with its byte saving, appears as you type. Untick the licence option if you also want /*! */ comments removed, then copy the output.
- Paste your JavaScriptPaste a script, function or snippet. Template literals, arrow functions and optional chaining are fine.
- Decide on licence commentsKeep /*! … */ licence comments is on by default; untick it to remove every comment.
- Copy the resultCheck the byte count and copy the code. Run your tests against the minified file before deploying it.
Before and after: what changes
The sample function is 219 bytes and minifies to 150 bytes, 31.5% smaller. Comments go, including one placed after a string that itself contains //, because the code is split into tokens first. count = count - -1 becomes count=count- -1: the space stays because a--1 would mean something different. The sample also leaves out semicolons, so line breaks are kept between those statements, where automatic semicolon insertion relies on them. That is why the output is not always a single line.
How this differs from Terser or esbuild
Only comments and whitespace are removed. Variables are not renamed, dead code is not dropped and statements are not merged, so the output stays readable and the saving is smaller than a build tool such as Terser or esbuild would give. That makes it a good fit for inline scripts, small snippets and quick checks, not for protecting source code. JSX and TypeScript are not plain JavaScript, so compile them first; the tokeniser does not understand JSX tags or type annotations.
Accuracy and data handling
After adding generated code to a project, test it in the target browsers and responsive sizes. The calculation runs in your current browser; the tool code does not send the input to a processing API.
FAQ
Why is my minified code still on several lines?
When statements aren't ended with semicolons, some line breaks are what separates them. Removing those would change what the code does, so a line break is kept only where automatic semicolon insertion depends on it.
Does it obfuscate or rename variables?
No. Names, structure and logic are untouched; only comments and whitespace go. Anyone can still read the result, so it isn't a way to hide source code.
My code fails after minifying. What should I check?
First confirm the original runs. Strings, regular expressions and template literals are kept exactly, so the usual cause is JSX or TypeScript syntax, which must be compiled to plain JavaScript first.
More Frontend Tools
Related toolsIndent messy or minified HTML into readable, nested lines, including inline CSS and JS.
Unminify CSS into tidy, indented rules with one declaration per line.
Reformat compressed JavaScript into indented, readable code without touching strings.
Convert between px, rem, em, % and pt using your own root and parent font sizes.
Build fluid clamp() font sizes and spacing that scale between two viewport widths.
Score CSS selectors as (A, B, C) and rank them by specificity.