minify-html is a Python binding for an extremely fast and smart HTML + JS + CSS minifier written in Rust. It offers advanced minification strategies that outperform other minifiers in both speed and effectiveness, handling invalid HTML and templating syntax. The library is actively maintained with frequent minor releases, often multiple times a month, and is currently at version 0.18.1.
pip install minify-htmlVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to minify an HTML string, including inline CSS and JavaScript, while configuring options like comment removal and doctype preservation.
Use `snake_case` keyword arguments directly when calling the `minify` function (e.g., `minify(html, keep_comments=False)`).
Ensure the Go compiler is installed in your environment if you encounter issues with JS/CSS minification during a custom build or non-standard installation. For typical usage with pre-built wheels, this is generally not an issue.
Review the available configuration options such as `keep_spaces_between_attributes` or `keep_html_and_head_opening_tags` to fine-tune whitespace preservation if unexpected rendering issues occur. Test minified output thoroughly in your target browsers.
Install the library using pip: `pip install minify-html`
Ensure you are calling the `minify` method on the imported module: `import minify_html; minified_html = minify_html.minify(html_content_string)`
Install Rust and Cargo using the official `rustup` script (`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`) or your system's package manager, then retry `pip install minify-html`.
Adjust minification options to be less aggressive. For example, explicitly keep spaces between attributes or disable optimal entity encoding: `minify_html.minify(html_string, keep_spaces_between_attributes=True, allow_optimal_entities=False)`
No dependency data recorded yet.