How it works
Minifying source files requires structured syntax execution loops rather than blunt string substitutions to avoid breaking programmatic references. Our tool implements a 100% client-side compilation model that applies optimization rules in sequential phases:
1. The Tokenization Scan (Lexical Analysis)
The raw input string undergoes sequential character analysis to categorize active programmatic segments. Rather than using simple global regular expressions, a strict tokenization state machine maps content boundaries into distinct types:
- Literal Code blocks (Functions, definitions, keywords)
- String Contexts (Single quotes, double quotes, and ES6 backtick templates)
- Regex literals (Forward-slash encapsulated patterns)
- Comments (Single line
// and block-level multi-line /* */)
By locking strings and regular expressions into immune token boundaries, the optimizer guarantees that text inside your alerts, logs, and regex patterns is never accidentally modified or stripped away.
2. Comment Filtering and Rule Sweeping
Depending on your chosen preset settings (Basic vs. Aggressive), the program filters the token array:
- License Preservation: Retains necessary open-source notifications or standard copyright header layouts if requested.
- Diagnostic Stripping: Discovers and purges diagnostic references like
console.log() statements or explicit line debugger assertions to compress production weight.
3. Structural Minification and Compression
Once token contexts are filtered, the code structures undergo granular code-reduction rules:
- Whitespace Removal: Erases sequential spacing blocks, line breaks, indentation tabs, and trailing carriage returns.
- Operator Pruning: Condenses padding around algebraic, assignments, and structural characters (e.g.,
x = y + 5; scales directly down to x=y+5).
- Boolean Shorthand: Transforms verbose
true and false literals into optimized primitive byte sizes like !0 and !1 dynamically where safe.
4. Gzip Deflate Size Approximation
The statistics generator estimates compressed size using a simplified client-side model. Actual Gzip or Brotli output depends on the compressor and its settings.