JS Minifier

Compress JavaScript by removing comments, whitespace, and unnecessary characters to reduce file size and improve load performance.

Input JavaScript
Minified JavaScript
⚠️ This is a basic minifier. It removes comments and collapses whitespace but does not rename variables or perform dead-code elimination. For production use, consider a full-featured bundler like esbuild or Terser.

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

  1. Paste your JavaScript source code — including any comments and indentation — into the Input JavaScript text area on the left.
  2. 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.
  3. Click the Minify JS button to compress the code. The minified output appears in the right panel.
  4. Review the statistics bar below: it shows the original size, minified size, and the percentage and byte amount saved.
  5. 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

This tool is string-literal aware, so it correctly identifies comment-like patterns inside strings and does not remove them. It also handles both types of comments (single-line and block) independently. However, it does not perform full AST parsing, so edge cases involving regex literals that contain // sequences, or nested template literals, may not process correctly. Test the output on complex code before deploying it.
No. All minification runs entirely in your browser using JavaScript. Your source code is never transmitted to Oneyfy's servers or any third party. The processing happens locally in browser memory, making it safe to use with confidential, proprietary, or licensed code that should not leave your environment.
Yes, completely free. No account is required, there are no usage limits, and there is no charge for any number of minifications. The tool is available at no cost for personal and commercial use.
Results vary depending on how much of the file is comments and whitespace. A well-documented script with many comments and consistent 4-space indentation can see 30–50% size reduction from comment and whitespace removal alone. A script with minimal comments and tight formatting might only see 5–15%. Variable renaming (not done by this tool) typically adds another 20–30% reduction on top of whitespace removal.
Terser and UglifyJS are full AST-based minifiers that parse JavaScript into a complete syntax tree before optimizing it. They can rename variables to shorter names, remove dead code, inline constants, and perform many other optimizations. This tool performs only comment removal and whitespace collapsing — the simplest form of minification — without renaming or AST analysis. It is faster and simpler but produces less aggressive compression than a full minifier.
Yes. The layout is responsive and the tool works in mobile browsers on Android and iOS. Pasting large scripts is easiest with a physical keyboard. The minification process itself is very fast even on mobile devices for typical script sizes under 500KB.