Skip to content
ToolsMinify logo
Developer Tools
Popular

JavaScript Minifier

Free online JavaScript minifier. Compress and minify JS by removing comments and collapsing whitespace - smaller files, faster page loads. Runs in your browser, no upload required.

About JavaScript Minifier

Minify JavaScript instantly in your browser. Paste your script to strip comments, remove indentation and blank lines, and collapse extra whitespace - producing a smaller .js file that downloads and parses faster. This is a safe, basic minifier: it protects the contents of your strings, template literals, and regular expressions, and keeps the line breaks between statements so Automatic Semicolon Insertion still works exactly as before. It shows precisely how many bytes you saved, and everything runs client-side, so your code never leaves your device. For maximum compression - variable renaming and dead-code removal - pair it with a build tool such as Terser or esbuild.

How to Use JavaScript Minifier

  1. Paste or type your JavaScript into the input box.
  2. Click Minify JavaScript to remove comments and collapse extra whitespace.
  3. Review the bytes saved and the percentage reduction shown above the output.
  4. Click Copy to grab the minified JavaScript for your project or page.

JavaScript Minifier Examples

Remove comments and indentation

A commented, indented function like function add(a, b) {\n // sum\n return a + b;\n} becomes function add(a, b) {\nreturn a + b;\n} - smaller and identical when run.

Preserve strings and regex

Text inside strings, template literals, and regular expressions is never touched, so a URL like "https://example.com" or a pattern like /a\/b/g keeps working.

Keep line breaks for safety

Statement line breaks are preserved so code that relies on Automatic Semicolon Insertion behaves exactly the same after minifying.

Read the full guide

How to Use JavaScript Minifier: Complete Guide (2026) - 5 min read

Frequently Asked Questions about JavaScript Minifier

What does a JavaScript minifier do?
A JavaScript minifier reduces the size of a .js file without changing what it does. It removes the characters the engine ignores - comments, indentation, line breaks, and repeated spaces - so the file downloads and parses faster. This tool focuses on the reductions that are always safe: it strips comments and collapses whitespace while keeping the line breaks between statements intact.
Does minifying JavaScript change how my code runs?
No. This is a safe minifier: it only removes comments and whitespace that do not affect execution, and it protects the contents of strings, template literals, and regular expressions. It also keeps the newlines between statements, so code that depends on Automatic Semicolon Insertion keeps working exactly as before.
Is my JavaScript uploaded to a server?
No. All minification happens entirely in your browser using JavaScript. Your code is never sent to or stored on a server, which makes the tool safe for private scripts, unreleased features, and proprietary logic.
Will this rename variables or remove unused code?
No. This is a basic, safe minifier - it removes comments and collapses whitespace but does not rename variables, shorten identifiers, or remove dead code. For maximum compression, run a full build-time tool such as Terser, esbuild, or SWC, which parse the code into an AST and can rewrite it aggressively.
How much smaller will my JavaScript be?
It depends on how much whitespace and how many comments your file contains. Heavily formatted, well-commented source often shrinks by 20-40%, while already-compact code saves less. The tool shows the exact bytes saved and the percentage reduction so you can see the result for your specific file.
Should I minify JavaScript or just use gzip/Brotli?
Use both. Server compression (gzip or Brotli) already handles repeated whitespace well, so the over-the-wire difference from minifying alone is smaller than the raw byte saving. Minifying still helps: it shrinks the uncompressed size in caches and memory, gives the compressor less to do, and guarantees a smaller file even where compression is unavailable.
Is it safe for code that uses regular expressions?
Yes. The minifier recognizes regular-expression literals and protects their contents, so patterns like /a\/b/g are preserved and never mistaken for comments or division. It handles the common cases correctly; for unusual code where a regex appears in an ambiguous position, verify the output or use a parser-based tool.