๐ฆ JavaScript Minifier
function greet(name){
const message=`Hello, ${name}!`;
return message;
}
console.log(greet('World'));Strips comments and extra whitespace/indentation from JavaScript source code to reduce its file size. The contents of strings, template literals, and regular expression literals are left untouched โ only the surrounding code structure is compacted.
How to use
- Paste the JavaScript code you want to minify into the input box.
- The minified result appears automatically below.
- Click "Copy" to copy the minified code to your clipboard.
How the calculation works
This tool shrinks JavaScript by removing comments and unnecessary whitespace. It reads the code character by character: โข // and /* */ comments are removed โข the contents of strings ('โฆ', "โฆ"), template literals (`โฆ`) and regular expressions (/โฆ/) are kept exactly โข runs of spaces and tabs become a single space only where needed to separate words (var x, return a) โข spaces between symbols that would change meaning if joined, such as "- -" in "a - -b", are kept โข line breaks are collapsed but kept Whether "/" is division or the start of a regex is decided from the preceding character or word (return, typeof and so on). Line breaks are kept so JavaScript's automatic semicolon insertion behaves the same.
Worked example
Input // Returns the sum function add(a, b) { /* addition */ return a + b; } const x = 1 - -2; Output function add(a,b){ return a+b; } const x=1- -2; All comments are gone, and only the space in "1 - -2" is kept.
Things to be aware of
- This tool does not shorten variable names or remove unused code. For production builds, use Terser, esbuild or a build tool such as Vite.
- License comments such as /*! โฆ */ are removed too. If a licence requires them, add them back at the top.
- Your code is processed in the browser and never sent anywhere.
FAQ
Does this rename variables (mangling)?
No, this is a basic minifier that only strips comments and compacts whitespace. It doesn't perform advanced optimizations like variable renaming.
Are regular expression literals handled correctly?
Yes. Slashes inside strings or regex literals, like / or //, are distinguished from real comments so they're never stripped.
Will the minified code behave exactly like the original?
For most common code it will, but this tool doesn't guarantee correctness for every possible JavaScript syntax edge case. For production use, verify the minified output before shipping it.