JavaScript Minifier

Minify JavaScript code by removing comments and whitespace to reduce file size.

JavaScript Input
Minified Output
⚠️ This is a basic minifier (comment/whitespace removal only). It does not perform variable renaming or tree-shaking. For production builds, use a proper bundler like esbuild, terser, or webpack.

How to Use

1
Paste JavaScriptPaste your JavaScript code into the Input field.
2
Select optionsChoose what to remove: single-line comments, multi-line comments, whitespace, newlines.
3
Click MinifyThe minified code appears in the Output with size savings shown.
4
Copy resultCopy the minified JavaScript with the Copy button.
5
Test the resultAlways test minified JavaScript in your project to ensure it still works correctly.
📌 All processing happens locally in your browser. Your code is never uploaded to any server.

About JavaScript Minifier

JavaScript Minifier is a free, browser-based tool that reduces the size of your JavaScript files by stripping comments and collapsing unnecessary whitespace. Smaller JS files load faster, reduce bandwidth, and improve Lighthouse/PageSpeed scores. This tool is ideal for quick minification of small scripts, inline JS, or code you want to inspect after compression. Paste your code, select what to remove, click Minify JS, and see exactly how many bytes were saved — all without uploading your code anywhere.

Why Use JavaScript Minifier?

Faster Page Load Times Every kilobyte removed from your JS files means less data transferred and faster parse time. Minified scripts can be 30–60% smaller than the original, directly improving page speed and Core Web Vitals.
🔒
Code Never Leaves Your Browser Unlike online minifiers that upload your code to a server, everything here runs in your browser using JavaScript. Your proprietary code, API keys, or business logic stay completely private.
🎛️
Granular Control Choose exactly what to remove: single-line comments, multi-line comments, whitespace, or newlines independently. Useful when you need to preserve certain comment types (e.g. license headers).
📊
Instant Size Savings Report See exactly how many bytes were removed and the percentage reduction. Useful for quickly auditing inline scripts or small utility files before adding them to a project.

Frequently Asked Questions

This is a basic regex-based minifier that removes comments and whitespace. It does NOT rename variables, inline functions, perform dead code elimination, or do advanced AST-based optimizations. For production, use terser or esbuild.
There's a small risk. Removing newlines can affect Automatic Semicolon Insertion (ASI) in rare cases. Code that relies on comments (like directive prologs or TypeScript annotations) may also be affected. Always test the output.
For production builds: terser (standalone or via webpack), esbuild (extremely fast), swc (Rust-based), or Google Closure Compiler. These perform full AST analysis for maximum compression with safety.
Usually no. Regular comments are for humans. However, some special comments serve functional purposes: /*! ... */ license preservation comments, @license tags, and sourcemap comments (//# sourceMappingURL=). These will also be removed.