mkdocs-minify-html-plugin

raw JSON →
0.3.10 verified Fri May 01 auth: no python

MkDocs plugin that minifies HTML, JS, and CSS output using the blisteringly fast minify-html Rust-based minifier. Current version 0.3.10, released June 2024. Active development with semver.

pip install mkdocs-minify-html-plugin
error AttributeError: module 'mkdocs_minify_html_plugin' has no attribute 'MinifyHTMLPlugin'
cause Wrong import: importing the module instead of the class or using hyphens.
fix
Use: from mkdocs_minify_html_plugin import MinifyHTMLPlugin
error ModuleNotFoundError: No module named 'minify_html'
cause Misspelled package name: installing 'minify-html' instead of 'mkdocs-minify-html-plugin'.
fix
Install the correct package: pip install mkdocs-minify-html-plugin
error Config error: Unrecognised configuration key: 'js'
cause Using old option names from pre-0.3.0.
fix
Replace 'js' with 'minify_js' and 'css' with 'minify_css' in mkdocs.yml.
breaking From version 0.3.0, the option names changed: 'minify_js' and 'minify_css' replaced 'js' and 'css'. The old names silently fail.
fix Update your mkdocs.yml: replace 'js: true' with 'minify_js: true', same for css.
gotcha The plugin must be listed after 'search' in the plugins list to ensure minification runs after search index generation.
fix Order: start with 'search', then add 'minify-html'.
deprecated The 'htmlmin_opts' sub-options are deprecated as of 0.4.0 (unreleased). Use top-level options instead.
fix Migrate 'htmlmin_opts.remove_comments' to 'remove_comments: true' (once 0.4.0 lands). For now, both work.
gotcha The plugin does not minify inline CSS/JS inside <style> and <script> tags by default. Set 'minify_inline_css' and 'minify_inline_js' if needed.
fix Add 'minify_inline_css: true' and 'minify_inline_js: true' to your plugin config.

Enable the plugin in your MkDocs configuration. The plugin automatically minifies all HTML, JS, and CSS output during build.

# mkdocs.yml
plugins:
  - search
  - minify-html:
      minify_js: true
      minify_css: true
      htmlmin_opts:
        remove_comments: true
        collapse_whitespace: true