Developer Tools

JavaScript Minifier

Remove comments and compact whitespace from JavaScript code to reduce file size. This text-based tool strips line and block comments, collapses whitespace, and trims punctuation spacing.

Run tool

The JavaScript Minifier helps you reduce the size of your JavaScript code by removing comments and compacting whitespace. It works by stripping line comments starting with // and block comments, then collapsing runs of whitespace into single spaces, trimming leading and trailing spaces, and removing spaces around braces, parentheses, semicolons, commas, and colons. The tool is text-based, not syntax-aware, so comment-like text inside strings or other constructs may be altered. After processing, you get the minified code along with original and transformed character counts, the number of characters removed, and the percentage saved rounded to one decimal place. The tool accepts any JavaScript text input and works with both blank and non-blank content. For empty or whitespace-only input, it returns empty transformed text with zero counts. Use it to quickly see how much space you can save by removing comments and unnecessary whitespace from your code.

Instructions

  1. Paste or type your JavaScript code into the input field labeled Js Code.
  2. Click the Run button to process the code.
  3. View the minified output in the result panel, along with character counts and the percentage saved.

Examples

  • Input: // This is a comment\nfunction hello() {\n console.log('Hello');\n}\nOutput: function hello() {console.log('Hello');} with 48 characters removed (68.6% reduction).
  • Input: /* Block comment */ var x = 10; // inline\nOutput: var x = 10; with 28 characters removed (68.3% reduction).
  • Input: (empty or whitespace only)\nOutput: empty string with 0 characters removed.

FAQ

Does this tool remove all comments from my JavaScript?

The tool removes line comments (//) and block comments (/* */). However, because it works on text patterns, comment-like text inside strings or other constructs might be altered.

What happens if I enter empty or whitespace-only code?

The tool returns an empty transformed string with zero original and transformed character counts.

Does the tool preserve JavaScript syntax?

The tool operates on text patterns, not JavaScript syntax. It may alter comment-like text inside strings or other constructs, so review the output carefully.

Can I use this for production minification?

Yes, it is useful for quick minification, but for production, consider using a syntax-aware minifier to avoid unintended changes to strings or other constructs.

What metrics does the tool provide?

It shows the original character count, transformed character count, number of characters removed, and the percentage saved rounded to one decimal place.

Embed this tool

Add this working SmartPlusLab tool to your website with the code below.