JavaScript Minifier
Reduce JS file size by removing comments and whitespace
Cut the size of a script before you ship it
Comments, indentation and blank lines help humans but cost bytes when a browser downloads your script. The JavaScript Minifier collapses your code into a compact single-line form and can optionally remove debugging output, giving you a smaller file to paste into a page, a bookmarklet or an embed snippet.
Using it
- Paste code into Source Script, or click Load Sample to see a tiny function with a comment.
- Review the three checkboxes under Advanced Options: Mangle Variables (Experimental), Remove console.* Logs and Remove All Comments. The last two are ticked by default.
- Click Minify JavaScript.
- Read the Compressed Code panel, check the size and character count shown beneath it, and press Copy.
What each option really does
- Remove All Comments deletes block comments and line comments.
- Remove console.* Logs strips calls to console.log, debug, info, warn, error, table and dir. It matches from the call to the end of the line, so a console call sitting on the same line as other code can take that code with it.
- Mangle Variables renames names declared with var, let or const into short identifiers like _0x0. It is a plain text substitution, not a full parser, which is why it is marked experimental.
Whitespace is collapsed and the spaces around symbols such as braces, semicolons, commas and operators are removed.
Practical uses
- Trimming an inline script for an email template or landing page where every kilobyte counts.
- Creating a compact copy of a small utility to paste into a bookmarklet.
- Removing leftover debug logging before sharing a snippet.
- Getting a quick before-and-after size comparison to decide whether a real build pipeline is worth setting up.
Cautions
This is a lightweight text-based minifier, not a full compiler like Terser. Because it joins lines into one, code that depends on automatic semicolon insertion, or that has a line comment inside a template literal or regular expression, can break. Always run the minified output through your tests, and keep the original file. Leave Mangle Variables off for code that uses names in strings, such as eval or dynamic property lookups. Processing happens in your browser.
Related Articles
Related Tools