← Blog dev

A regex-based JS minifier can quietly break your code. We used the same parser major bundlers use instead.

Scan to open this page

A regex-based JS minifier can quietly break your code. We used the same parser major bundlers use instead.

Before building our JavaScript minifier/formatter, we checked a popular tool directly and looked into the core risk that makes JS minification different from CSS or HTML.

Why "safe" matters more for JS than any other minifier

A minifier that just strips whitespace with regular expressions is fine for CSS, but JavaScript has string literals, regex literals, and automatic semicolon insertion — a naive regex-based implementation can easily misread a / as a comment start inside a regex literal, or drop a semicolon that changes what a line actually does. That's a real, documented failure mode for this category of tool: getting it wrong doesn't just look ugly, it changes what your code does. We avoided the risk entirely by using terser — the same parser bundled inside major JavaScript bundlers — instead of writing our own regex pass.

License comments, kept on purpose

Like CSS's /*! convention, JavaScript has a documented practice of preserving comments starting with /*!, or containing @license or @preserve, through minification — terser follows this by default. We tested it directly: a /*! MyLib v1.0 - Copyright 2026 */ comment survives minification here, and we confirmed the minified output still runs and produces the exact same result as the original.

Live, with a number you can act on, and no crash on bad input

We checked toptal.com's JavaScript minifier directly — it requires clicking "Minify" for every change. This tool updates as you type (debounced), and Minify mode shows the exact byte-size reduction. We also fed it deliberately broken JavaScript to confirm it never crashes: instead of a blank screen or scary browser exception, it shows a plain-language message explaining what couldn't be parsed.

Try the JavaScript minifier/formatter →

#JavascriptMinifier#JavascriptMinifierSafeWontBreakCode#JavascriptMinifierLiveNoButton#JavascriptMinifierPreservesLicenseComment