Skip to content
CODE FORMATTING & MINIFICATION

JavaScript Minifier – Minify JS Online

Remove comments and unnecessary whitespace from JavaScript.

  • Free
  • No signup
  • Runs in your browser

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

JavaScript Minifier

About JavaScript Minifier

This JavaScript minifier removes comments and unnecessary whitespace, including spaces around operators, brackets and commas. Strings and template literals are copied exactly, so text inside quotes is never altered.

Line breaks that could change how the script is parsed are kept, which protects code that relies on automatic semicolon insertion. Because the tool does not rename variables or restructure code, the output is larger than the result of Terser or esbuild, but it is predictable and easy to check.

How to use JavaScript Minifier

  1. Paste your JavaScript into the input box.
  2. Click Run Tool to minify it.
  3. Copy the result and run your tests or load the page to confirm it still works.

Example

Input

// add two numbers
function add(a, b) {
  return a + b; /* sum */
}
const label = "keep  these  spaces";
console.log( add( 1, 2 ), label );

Output

function add(a,b){return a + b;}
const label="keep  these  spaces";console.log(add(1,2),label);

Common uses

  • Shrinking a small inline script or bookmarklet.
  • Removing comments from a snippet before you share it.
  • Comparing the size of a script before and after whitespace removal.

Privacy and safety

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

Frequently asked questions

Will it break my code?

For normal code it should not, but regular expression literals that contain quotes or comment markers can be misread. Always test the minified script.

Does it shorten variable names?

No. Name mangling needs a full parser. Use Terser, esbuild or your bundler for production builds.

Does it support modern syntax?

Yes for whitespace purposes. Arrow functions, classes, async functions and template literals are all handled because the tool only works with text, not syntax trees.

Learn to build this yourself

Free tutorials and courses on NHP Learning cover PHP, JavaScript, SQL and WordPress, from the basics to real projects.