MkDocs Minify Plugin
An MkDocs plugin designed to minify HTML, JavaScript, and CSS files before they are written to disk. It leverages `htmlmin2` for HTML, `jsmin` for JavaScript, and `csscompressor` for CSS minification. The project is actively maintained, with regular updates addressing compatibility and feature enhancements.
Warnings
- breaking MkDocs 1.5 compatibility was introduced in plugin version 0.7.0. If you are using MkDocs 1.5 or newer, you must use mkdocs-minify-plugin version 0.7.0 or later to ensure compatibility and avoid potential build errors.
- gotcha When you explicitly define a `plugins` section in your `mkdocs.yml`, MkDocs no longer implicitly enables the built-in `search` plugin. To retain search functionality alongside `minify`, you must explicitly list `search` in your `plugins` section.
- gotcha Enabling `minify_js: true` or `minify_css: true` alone is not sufficient. You must also specify the JavaScript and CSS files to be minified using the `js_files` and `css_files` options (which support glob patterns).
- deprecated Versions prior to 0.6.2 might experience issues with minifying modern ES6 JavaScript due to `jsmin` not always being called with the appropriate `quote_chars` option.
- deprecated Versions prior to 0.6.3 may produce a `DeprecationWarning` related to an older `htmlmin` dependency during the build process.
Install
-
pip install mkdocs-minify-plugin
Quickstart
plugins:
- search # Often needed, see warnings
- minify:
minify_html: true
minify_js: true
minify_css: true
htmlmin_opts:
remove_comments: true
cache_safe: true
js_files:
- '**/*.js'
css_files:
- '**/*.css'