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
- Paste your JavaScript into the input box.
- Click Run Tool to minify it.
- 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.