What minifying removes
JavaScript minification removes the parts the engine ignores — line comments (//…), block comments (/*…*/), indentation and surplus blank lines — leaving a compact file that runs byte-for-byte the same. Smaller scripts download and parse faster.
This minifier is a fast, dependency-free whitespace compressor: it strips comments and collapses runs of whitespace while protecting strings, template literals and regular expressions, so text inside quotes is never altered.
Worked example
A commented helper collapses neatly:
function add(a, b) { /* sum */ return a + b; } with comments and indentation.function add(a,b){return a+b;}Limits and safety
This is a lightweight whitespace-and-comment minifier, not a full mangler — it does not rename variables or remove dead code the way build tools such as Terser do, so it is safe to run without a parser and won't break valid code. It keeps newlines where removing them could change meaning (after return, break, etc.) so automatic semicolon insertion still works. For production builds, a bundler will squeeze out more. Everything runs locally — your code never leaves the browser.