JavaScript Minifier
Paste your JavaScript below to minify it instantly. Remove comments, collapse whitespace, and see how much space you save.
How to Use the JavaScript Minifier
Minifying JavaScript is one of the simplest and most effective ways to improve your website's performance. This free online JavaScript minifier removes unnecessary characters from your source code — comments, extra whitespace, and empty lines — without changing how the code behaves. The result is a smaller file that downloads faster and improves page load times for your users.
- Paste your code: Copy your JavaScript from a source file, code editor, or browser console and paste it into the input textarea above.
- Click Minify: The tool processes your code instantly, stripping comments and collapsing whitespace to produce a compact version.
- Review the stats: Check the original size, minified size, and savings percentage shown below the buttons. This tells you exactly how much space you saved.
- Copy the result: Click the Copy button to copy the minified code to your clipboard, ready to paste into your project or deployment pipeline.
What Gets Removed During Minification
Understanding what the minifier removes helps you trust that your code will still work correctly after processing. Here is a breakdown of the transformations applied:
| Transformation | Description |
|---|---|
| Block comments | Multi-line comments wrapped in /* ... */ are removed entirely |
| Line comments | Single-line comments starting with // are stripped |
| Extra whitespace | Multiple consecutive spaces and tabs are collapsed to a single space |
| Empty lines | Blank lines with no content are removed from the output |
| Leading/trailing space | Whitespace at the start and end of each line is trimmed |
Minification vs Obfuscation
Minification and obfuscation are often confused but serve different purposes. Minification reduces file size by removing unnecessary characters while keeping variable names and code structure intact. Obfuscation deliberately makes code difficult to read by renaming variables, encoding strings, and restructuring logic. This tool performs minification only — it makes your code smaller without making it harder to understand. If you need obfuscation for intellectual property protection, use a specialised tool like javascript-obfuscator.
Tips for Maximum Savings
- Add JSDoc comments during development for documentation, then minify for production — the comments will be stripped automatically.
- Use consistent formatting in your source code so the minifier can collapse whitespace effectively.
- Combine minification with gzip or Brotli compression on your server for even greater file size reductions.
- For production builds, consider using a full build tool like Webpack, Rollup, or esbuild that can also perform tree-shaking and dead code elimination alongside minification.
Frequently Asked Questions
How does JavaScript minification work?
JavaScript minification removes unnecessary characters from source code without changing its functionality. This includes stripping out comments (both single-line // and multi-line /* */), collapsing multiple whitespace characters into single spaces, removing empty lines, and trimming leading and trailing whitespace from each line. The result is a smaller file that behaves identically to the original.
Will minification break my JavaScript code?
Basic minification that removes comments and whitespace should not break your code. However, this tool performs simple regex-based minification rather than full AST-based parsing. It preserves strings and avoids removing content inside string literals. For production use with advanced optimizations like variable renaming and dead code elimination, consider using dedicated build tools such as Terser or esbuild.
When should I minify my JavaScript?
Minify JavaScript before deploying to production to reduce file size and improve page load times. Smaller files mean faster downloads for users, lower bandwidth costs, and better Core Web Vitals scores. Keep the original unminified source in your development environment for readability and debugging, and use the minified version only for serving to end users.
How much file size reduction can I expect?
The savings depend on how much whitespace and how many comments your code contains. Heavily commented and well-formatted code can see reductions of 30–60%. Code that is already compact may only shrink by 10–20%. This tool shows you the exact original size, minified size, and savings percentage after each minification.