JS Minifier
Compress JavaScript by removing comments, whitespace, and unnecessary characters to reduce file size and improve load performance.
About JS Minifier — JavaScript Minifier Online
Paste JavaScript source code into the JS Minifier online and get back a compressed version — removing comments and collapsing whitespace to JavaScript source code by removing comments and collapsing whitespace, producing a smaller file that loads faster in production.The output is functionally identical; only the formatting is stripped.
Every kilobyte saved from a JavaScript file directly improves page load time and reduces bandwidth costs, particularly for users on mobile networks. Comments make code maintainable during development, but the browser ignores them entirely — they are pure overhead in production. Minifying your scripts before deployment is one of the simplest and most reliable web performance optimizations you can make. This tool handles the most impactful part of basic minification: comment stripping and whitespace collapsing.
How to Use the JS Minifier
- Paste your JavaScript source code — including any comments and indentation — into the Input JavaScript text area on the left.
- Select the minification options you want to apply using the checkboxes: Remove // comments, Remove /* */ comments, and Collapse whitespace. All three are checked by default for maximum compression.
- Click the Minify JS button to compress the code. The minified output appears in the right panel.
- Review the statistics bar below: it shows the original size, minified size, and the percentage and byte amount saved.
- Click the Copy button to copy the minified JavaScript to your clipboard for use in your project.
What the JS Minifier Does
This tool applies three safe transformations that can each be toggled on or off independently.
- Remove single-line comments (// ...): Strips all single-line comments from the code. The minifier is string-literal aware, so comment-like content inside string values (such as
"http://example.com") is never accidentally removed. Comments are identified only in the code context, not inside quoted strings. - Remove block comments (/* ... */): Strips all block comments including multi-line documentation comments. This is separate from the single-line option so you can keep inline documentation (
/* ... */) while removing line comments, or vice versa. License headers in the format/*! ... */are currently treated the same as regular block comments. - Collapse whitespace: Replaces multiple consecutive spaces and tabs with a single space, and removes leading and trailing whitespace on lines. Consecutive newlines are reduced to a single newline. This step has the largest impact on files with heavy indentation such as deeply nested switch statements or formatted object literals.
Tips for Getting the Best Results
Used correctly, even basic minification produces meaningful file size reductions in most real-world scripts.
- Combine minification with gzip or Brotli compression on your server: Minified code is already smaller, but it also compresses better than formatted code because repeated patterns are denser. A minified 30KB script compressed with gzip will often transfer as only 10–12KB. Configure your web server to serve JavaScript files with gzip or Brotli encoding for the best results.
- Always test minified output before deploying: This tool is string-literal aware but does not perform full AST parsing. Edge cases involving regex literals that contain
//or/*sequences could theoretically be mishandled. For scripts with complex regex patterns, test the minified output in your browser before deploying it to production. - Use this for quick fixes; use esbuild or Terser for production builds: This tool is ideal for one-off minification tasks and quick experiments. For a repeatable production build pipeline, use a dedicated bundler/minifier like esbuild or Terser that performs full AST-level optimization including variable renaming, dead code elimination, and constant folding.
- Keep your original formatted source files: Never overwrite your development source files with minified versions. Always maintain readable originals in version control and generate minified output as part of your build step or by using this tool to create a separate production file.
- Check the savings percentage to prioritize: The stats bar shows the savings as both a byte count and a percentage. If a file achieves only a 5% reduction, it has few comments and little whitespace — perhaps it was already partially minified. Focus your optimization effort on files that achieve 20%+ savings, as those have the most formatting overhead.
Why Use a JavaScript Minifier Online
Build tools like Webpack, Vite, and Rollup include minification in their production build pipeline automatically, but not every project uses a bundler. Simple scripts embedded in HTML files, small utility scripts, and standalone client-side tools often aren't part of a build system. For these cases, a browser-based minifier provides instant results without requiring Node.js, npm, or any configuration.
The tool processes code entirely in the browser, so your source code is never transmitted to any server. This is important for proprietary internal scripts, licensed third-party code you are optimizing for deployment, or any other code you aren't comfortable sending through an external service.
Frequently Asked Questions about JS Minifier
// sequences, or nested template literals, may not process correctly. Test the output on complex code before deploying it.