################## From minify-html ################## .. package-meta:: minify-html wilsonzlin/minify-html `minify-html `_ is a Rust HTML minifier with bindings for Python, Node, Deno, Ruby, Java, and a standalone CLI. ``minify_html.minify(html, **flags)`` collapses whitespace with a context-aware sensitivity model, drops the tags and attribute quotes the WHATWG rules make optional, strips comments, and can minify embedded CSS (via lightningcss) and JavaScript in the same pass. It targets maximum size reduction and is used to shrink HTML at build time and in response pipelines across those language ecosystems. turbohtml covers the same HTML folds with :func:`turbohtml.clean.minify`, one call that minifies a document over the WHATWG tree turbohtml already builds, configured by the frozen :class:`~turbohtml.Minify` options object. It collapses insignificant whitespace, omits the optional tags, unquotes attributes, strips comments, and optionally rewrites inline JavaScript and CSS, running the work in a compiled C serializer over the parsed tree rather than as a separate Rust pass. ************************** turbohtml vs minify-html ************************** .. list-table:: :header-rows: 1 :widths: 20 40 40 - - Dimension - turbohtml - minify-html - - Scope - Full WHATWG parser plus serializer; minify is one output layout of a queryable tree - Standalone string-in/string-out HTML/CSS/JS minifier - - Feature breadth - Whitespace, comment, optional-tag, and attribute-quote folds plus opt-in inline JS and CSS minification - The same HTML folds plus in-pass CSS and JS minification, template-syntax and SSI preservation flags, and more aggressive whitespace and attribute rewrites - - Performance - C serializer over an already-built tree; about 2x faster, parse included (see below) - Optimized Rust minifier, no tree retained - - Typing - Fully typed, frozen :class:`~turbohtml.Minify` options object - Untyped ``**flags`` keyword arguments - - Dependencies - Self-contained C extension, no runtime dependencies - Prebuilt Rust wheel, no runtime Python dependencies - - Maintenance - Actively maintained - Actively maintained across multiple language bindings Feature overlap =============== These HTML folds port one-to-one; each minify-html flag becomes a field on :class:`~turbohtml.Minify`: - Whitespace collapsing — on by default in both; maps to ``Minify(collapse_whitespace=True)`` (also the default). - Comment removal — ``keep_comments=False`` (the minify-html default) maps to ``Minify(strip_comments=True)`` (the turbohtml default; comments go unless you opt out). - Optional-tag omission — ``keep_closing_tags`` and ``keep_html_and_head_opening_tags`` map to the single ``Minify(omit_optional_tags=True)``, which drops the start and end tags the WHATWG rules make optional. - Attribute unquoting — on by default in both; maps to ``Minify(unquote_attributes=True)``. - Inline JavaScript minification — ``minify_js=True`` maps to ``Minify(minify_js=JSMinify())``, which rewrites ``