JavaScript Minifier

Minify JavaScript by removing comments and collapsing whitespace.

Input
Minified Output

Minified code will appear here

Note: Basic minifier: for production use, use a dedicated bundler like esbuild, Terser, or Webpack.

Free online JavaScript minifier: compress JS code in your browser

JavaScript is one of the largest contributors to page weight in modern web applications. Minifying your scripts before deployment reduces transfer size, speeds up parse time, and improves Core Web Vitals scores. This tool strips comments and collapses whitespace from any JavaScript code you paste, showing the resulting size reduction instantly.

This minifier is ideal for quick, ad-hoc compression of small scripts, inline JavaScript, or third-party code you want to evaluate. For production builds with many files, integrate a dedicated bundler. The note at the bottom of the tool reminds you of this distinction so you always use the right tool for the job.

Step-by-step guide

  1. 1
    Paste your JavaScript
    Copy your JavaScript code and paste it into the left input panel.
  2. 2
    Use Sample to test
    Click the Sample button to load an example script and see the minifier in action immediately.
  3. 3
    View the minified output
    The right panel shows the minified code in real time with comments stripped and whitespace collapsed.
  4. 4
    Review the size stats
    Check the Original Size, Minified Size, and Reduction percentage in the stats row below the panels.
  5. 5
    Copy and deploy
    Click Copy to grab the minified code and use it in your project, CDN, or build pipeline.

Related Tools

Frequently Asked Questions

What does a JavaScript minifier do?
A JavaScript minifier removes all non-essential characters from JS code: comments, extra whitespace, newlines, and redundant spaces around operators: to produce a smaller file that the browser executes identically.
Is minified JavaScript still valid and functional?
Yes. Minification removes only whitespace and comments, which are ignored by the JavaScript engine. The resulting code runs identically to the original.
Will this tool rename my variables?
No. This is a basic whitespace and comment minifier, not a full bundler. Variable and function names are left unchanged. For more aggressive minification including dead-code elimination and variable renaming, use Terser or esbuild in your build pipeline.
Is my code uploaded anywhere?
No. All minification runs in your browser using JavaScript. Your code never leaves your device.
Can I minify TypeScript with this tool?
TypeScript code that does not use type annotations can be minified here. TypeScript with type annotations must be transpiled to JavaScript first, then minified.
What size reduction can I expect?
Well-commented, generously formatted JavaScript typically sees 30–50% reduction. Code that is already compact may see 10–20% reduction, mainly from removing comments.
Why does the note recommend Terser or esbuild for production?
This tool uses a regex-based minifier that works well for simple scripts but cannot safely parse all valid JavaScript edge cases. Production builds should use Terser or esbuild which have full JS parsers, handle all edge cases correctly, and offer additional optimisations like tree shaking and dead code elimination.
Should I minify JavaScript before or after bundling?
Modern bundlers (Webpack, Vite, Rollup) apply minification as a final step of the bundle process. This tool is useful for ad-hoc scripts, third-party code you cannot control, or checking the output size before committing to a build tool.

AlteredIdea vs alternatives

vs server-side tools: Everything runs in your browser: your data never leaves your device.

vs VS Code extensions: No install needed. Works instantly in any browser.

vs paid tools: Completely free, no account required.