Tools

Home
JSON FormatterSQL FormatterJS ValidatorMinify CSS
Merge PDFCompress PDFImage to PDF
JPG to PNGPNG to WebPCrop Image

JavaScript Minifier

Paste your JavaScript code to minify by removing comments, whitespace, and unnecessary characters

Your files never leave your browser
Input0 chars, 0 lines
Output0 chars, 0 lines
Ready·
Note: This is a basic minifier that handles comment removal, whitespace collapsing, and simple optimizations. For production use, consider tools like Terser or UglifyJS which support dead code elimination, variable mangling, and full AST-based minification.

Paste your JavaScript, hit one button, and get a smaller file — comments gone, whitespace crushed, unnecessary characters stripped. No build tools, no config files, no npm install. And everything runs in your browser. Nothing gets uploaded.

How It Works

Paste JS Code
➔
Parse & Strip
➔
Minified Output

The minifier parses your JavaScript into an abstract syntax tree using Acorn, then rebuilds it without the extras. Comments get deleted, whitespace between tokens gets collapsed to the bare minimum, and semicolons are cleaned up. The result is functionally identical code that weighs less on the wire.

Examples

Stripping comments from a utility function

You documented every line during development. Production doesn't need those comments shipped to users.

INPUT
// Calculate tax amount function calcTax(price, rate) { // Default rate is 8.5% const r = rate || 0.085; return price * r; }
OUTPUT
function calcTax(price,rate){const r=rate||0.085;return price*r}

Shrinking an event handler block

Inline scripts in HTML emails or landing pages — every byte counts when you can't use external files.

INPUT
document.addEventListener("DOMContentLoaded", function () { const btn = document.getElementById("submit"); btn.addEventListener("click", function (e) { e.preventDefault(); console.log("clicked"); }); });
OUTPUT
document.addEventListener("DOMContentLoaded",function(){const btn=document.getElementById("submit");btn.addEventListener("click",function(e){e.preventDefault();console.log("clicked")})});

Cleaning up a config object

Config files tend to accumulate block comments and trailing whitespace over months of edits.

INPUT
/** * App configuration * Last updated: 2024-11-03 */ const config = { apiUrl: "https://api.example.com", timeout: 5000, // 5 seconds retries: 3 };
OUTPUT
const config={apiUrl:"https://api.example.com",timeout:5000,retries:3};

Who Uses This

👨‍💻 Frontend Devs

Quick-minify a script before dropping it into a CMS that doesn't have a build step.

📧 Email Developers

Squeeze inline JS into HTML emails where every kilobyte affects deliverability.

🎓 Students

See what minification actually removes so the concept clicks before learning Webpack.

🚀 Indie Hackers

Ship a landing page with one less build dependency by minifying the JS file manually.

Common Mistakes

Pasting code with syntax errors

The minifier has to parse your code before it can shrink it. A missing bracket or unclosed string will throw an error. Fix the syntax first, then minify.

Expecting variable renaming

This tool removes whitespace and comments — it doesn't mangle variable names. For that level of compression, you need Terser or a bundler with tree-shaking.

Minifying already-minified code

Running minified code through the tool again won't save more space. If the savings show 0%, the file is already minified. Try the beautifier first if you need to read it.

Technical Details

Frequently Asked Questions

Does minifying JavaScript break my code?

Not if the original code is valid. Minification removes whitespace and comments — it doesn't change logic. That said, always test the minified version. Some edge cases with regex literals or template strings can trip up simpler minifiers.

How much smaller will my JavaScript file get?

Depends on how much whitespace and how many comments your code has. Well-commented source files typically shrink 30-60%. Code that's already fairly compact might only drop 10-15%. The tool shows you the exact percentage right after minification.

What is the difference between minification and obfuscation?

Minification makes code smaller but still readable if you beautify it. Obfuscation rewrites variable names, adds dead code, and makes the logic intentionally hard to follow. This tool minifies only — it won't protect your source from being reverse-engineered.

Is it safe to paste proprietary code into an online minifier?

With this tool, yes. Everything runs in your browser using JavaScript — nothing gets sent to a server. You can verify this by opening your browser's Network tab while minifying. Zero requests go out.

Should I minify JavaScript for a small personal website?

If your script is under 5KB, the savings are tiny and probably won't affect load times. But it takes ten seconds, so why not? For anything over 20KB, minification is worth the effort — especially on mobile connections where every kilobyte matters.

Share: