Minifier ​
JavaScript minification plays a crucial role in optimizing website performance as it reduces the amount of data sent to users, resulting in faster page loads. This holds tremendous economic value, particularly for e-commerce websites, where every second can equate to millions of dollars.
However, existing minifiers typically require a trade-off between compression quality and speed. You have to choose between the slowest for the best compression or the fastest for less compression. But what if we could develop a faster minifier without compromising on compression?
Project Goals ​
We are actively working on a prototype that aims to achieve this goal, by porting all test cases from well-known minifiers such as google-closure-compiler, terser, esbuild, and tdewolff-minify.
Preliminary results indicate that we are on track to achieve our objectives. With the Oxc minifier, you can expect faster minification times without sacrificing compression quality.
Target Performance ​
- Speed: faster than Terser, competitive with esbuild
- Compression: Match or exceed Terser's compression ratio
- Correctness: Pass all major minifier test suites
Architecture Overview ​
Design Principles ​
The Oxc minifier is built around several key principles:
- Semantic-Aware: Uses semantic analysis to enable safe optimizations
- Incremental: Designed for incremental compilation workflows
- Configurable: Supports various optimization levels and targets
- Correct: Prioritizes correctness over aggressive optimization
Current Status ​
Implemented Features ​
- âś… Dead Code Elimination: Remove unreachable code
- âś… Constant Folding: Evaluate constant expressions
- âś… Tree Shaking: Remove unused exports (basic)
- âś… Variable Merging: Merge variable declarations
- âś… Statement Merging: Combine compatible statements
- âś… Name Mangling: Shorten variable and function names
- âś… Control Flow Optimization: Simplify control structures
- âś… Function Inlining: Inline small functions
- âś… Advanced Tree Shaking: Cross-module optimization
Performance Optimization ​
Key strategies for maintaining performance:
- Minimal AST Traversals: Combine multiple optimizations in single passes
- Efficient Data Structures: Use arena allocation and compact representations
- Early Termination: Skip optimizations when no benefit is possible