How to Minify JavaScript Online
Paste your JavaScript
Copy your source code into the Input JavaScript box. The tool runs entirely in your browser, so nothing is uploaded to a server. You can paste a single function or a full script file.
Click Minify JS
Press the Minify JS button. The tool strips single-line and block comments, collapses runs of whitespace, and removes spaces around common operators and punctuation such as braces, semicolons, commas, and parentheses.
Check stats and copy
Review the size readout showing original size, minified size, and bytes saved with a percentage. Use Copy Result to grab the output, or Clear to reset both fields and start over.
What This Minifier Does and Does Not Do
This tool performs lightweight, regex-based minification in your browser. It is fast and good for quick size reduction, but it is not a full JavaScript parser. The table below shows which transformations are applied so you can set expectations before pasting production code.
| Transformation | Applied | Notes |
|---|---|---|
| Remove line comments (//) | Yes | Matched by pattern, including any that appear inside string literals. |
| Remove block comments (/* */) | Yes | Removed everywhere, including inside strings or regex literals. |
| Collapse whitespace and newlines | Yes | Multiple spaces, tabs, and line breaks become a single space. |
| Trim spaces around operators | Yes | Applies to braces, semicolons, commas, and arithmetic or logical operators. |
| Rename or shorten variables | No | Identifier names are left unchanged. |
| Dead code removal or tree shaking | No | Use a bundler such as Terser or esbuild for those optimizations. |
When to Use This Tool
Quick size checks
Great for pasting a snippet and instantly seeing how many bytes comments and whitespace add. The stats line gives you original, minified, and percent saved at a glance.
Inline scripts and demos
Handy for shrinking small inline scripts, code samples, or bookmarklets where running a full build pipeline would be overkill.
Production bundles
For shipping production code, prefer a dedicated minifier like Terser, esbuild, or your bundler. They parse the syntax and rename variables for far smaller, safer output.
Code with tricky strings
If your code contains URLs, regex literals, or comment markers inside strings, test the output carefully. A regex-based pass can alter content it cannot tell apart from real comments.
Common Problems and Fixes
Minified code throws errors
This minifier collapses newlines into spaces and does not add semicolons. If your code relies on automatic semicolon insertion across line breaks, add explicit semicolons at statement ends before minifying.
Part of a string disappeared
The tool removes anything matching // or /* */ even inside string literals. If a string contains a URL like https://example.com or comment-like text, the trailing part may be stripped. Escape or split such strings, or use a syntax-aware minifier instead.
Regular expressions break
Slashes in regex literals can be misread as comment markers, and operator spacing rules can run characters together. Review any code that uses inline regular expressions after minifying.
Copy button does nothing
Copying uses the browser clipboard API, which requires a secure context. Make sure the page is loaded over HTTPS and that the output box is not empty before clicking Copy Result.