minify-html

Extremely fast Rust HTML, JS, and CSS minifier with an advanced minification strategy.

Library
Cargo
v0.18.1
1,166stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
42/100Fair
Development Activity0
Maintenance20
Community48
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture80
Code Quality74
Innovation82
Learning Curve66

minify-html is a Rust HTML minifier meticulously optimized for both speed and effectiveness. It applies an advanced context-aware minification strategy that beats other minifiers on output size while remaining much faster, handles invalid HTML and templating syntax gracefully, and delegates JS and CSS minification to oxc and lightningcss. The core crate powers bindings for Node.js, Deno, Python, Ruby, Java, and WASM.

What You Get

  • A fast minify function that takes HTML bytes and a configuration and returns minified output
  • Context-aware whitespace and markup handling that tolerates invalid HTML and templating syntax
  • Built-in JS and CSS minification via oxc and lightningcss
  • A shared core behind official Node.js, Deno, Python, Ruby, Java, and WASM bindings

Common Use Cases

  • Shrinking rendered HTML pages in a build step or at response time
  • Minifying HTML email and template fragments before delivery
  • Reducing payload size in static site and SSR pipelines

Under The Hood

Architecture — The minify-html crate is one member of a Cargo workspace that also holds the minhtml CLI, an even-faster minify-html-onepass variant, and per-language binding crates. Inside the crate, parse/ builds an AST (ast/) from input bytes, cfg/ defines the configuration surface, minify/ applies the optimization passes per element context, and entity/ and tag/ hold entity and tag tables. Embedded JS and CSS are handed to oxc and lightningcss.

Tech Stack — Rust 2018 edition. Dependencies include ahash and aho-corasick for fast lookups, memchr for scanning, once_cell for lazy tables, and the oxc suite (allocator, parser, codegen, minifier, span) plus lightningcss for JS/CSS. The release profile enables LTO, a single codegen unit, and stripping for a tight binary.

Code Quality — The crate carries an in-tree src/tests module, and the workspace ships a dedicated bench/ harness comparing against html-minifier and minimize on real top web pages, plus debug/ diff tooling for canonicalization. The monorepo layout keeps the core minifier decoupled from the language bindings.

API Design — The Rust surface is a single minify(bytes, &cfg) call with a Cfg struct of toggles, which maps cleanly onto every binding. Choosing between the default and onepass crates is the main decision; both share the same mental model, so moving between speed and thoroughness is straightforward.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search