Registry / web-framework / mkdocs-minify-plugin

mkdocs-minify-plugin

JSON →
library0.8.0pypypiunverified

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.

pip install mkdocs-minify-plugin
INSTALL
IMPORT
SIG · MKDOCS-MINIFY-PLUG
M
mkdocs-minify-plugin
web-frameworkpythonv0.8.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Add the `minify` plugin to your `mkdocs.yml` file under the `plugins` section. Remember to also explicitly add the `search` plugin if you don't have other plugins defined, as MkDocs disables default plugins when a `plugins` section is present. Configure `minify_html`, `minify_js`, `minify_css`, and specify `js_files`/`css_files` for minification.

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'
Debug
Known issues
breakingMkDocs 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.
fix
Upgrade mkdocs-minify-plugin to version 0.7.0 or higher: `pip install --upgrade mkdocs-minify-plugin`.
affects: <0.7.0
gotchaWhen 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.
fix
Ensure your `plugins` section includes `- search` if desired: `plugins: \n  - search \n  - minify: ...`.
affects: All versions
gotchaEnabling `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).
fix
Provide explicit `js_files` and `css_files` lists when enabling JS/CSS minification, for example: `js_files: ['**/*.js']`.
affects: All versions
deprecatedVersions 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.
fix
Upgrade to `mkdocs-minify-plugin` version 0.6.2 or newer to improve JavaScript minification compatibility: `pip install --upgrade mkdocs-minify-plugin`.
affects: <0.6.2
deprecatedVersions prior to 0.6.3 may produce a `DeprecationWarning` related to an older `htmlmin` dependency during the build process.
fix
Upgrade to `mkdocs-minify-plugin` version 0.6.3 or newer to resolve the `htmlmin` deprecation warning: `pip install --upgrade mkdocs-minify-plugin`.
affects: <0.6.3
Errors
Common errors & fixes
ERROR - Config value 'plugins': The "minify" plugin is not installed
This error occurs when the 'minify' plugin is referenced in `mkdocs.yml` but the `mkdocs-minify-plugin` Python package has not been installed, or the environment where MkDocs is building does not have it available.
fix
Install the plugin using pip: `pip install mkdocs-minify-plugin`.
minify_js: true` or `minify_css: true` without `js_files` or `css_files` specified
The `mkdocs-minify-plugin` requires explicit lists of JavaScript (`js_files`) or CSS (`css_files`) files to minify when `minify_js` or `minify_css` is set to `true`, as it does not automatically discover all files.
fix
When `minify_js: true` or `minify_css: true` is enabled in `mkdocs.yml`, you must specify the files to be minified. For example: `plugins: - minify: minify_js: true js_files: - 'js/extra.js' minify_css: true css_files: - 'css/extra.css'`
minify_html conflict with mkdocs-mermaid2-plugin
This issue indicates a known compatibility problem where the `minify_html` feature of `mkdocs-minify-plugin` interferes with the rendering or functionality of the `mkdocs-mermaid2-plugin`.
fix
There is no general one-size-fits-all fix as it's an ongoing compatibility issue. Possible workarounds might include disabling `minify_html` if Mermaid diagrams are critical, adjusting the order of plugins in `mkdocs.yml`, or checking for updated versions of either plugin that resolve the conflict.
Upgrade
Version history
0.8.0latest on PyPI · released Jan 29, 2024
Audit
Dependencies
mkdocsrequiredCore dependency for any MkDocs plugin; requires >=1.4.1 for compatibility.
htmlmin2requiredUsed for minifying HTML content; requires >=0.1.13.
jsminrequiredUsed for minifying JavaScript files; requires >=3.0.1.
csscompressorrequiredUsed for minifying CSS files; requires >=0.9.5.
pythonrequiredRequires Python version >=3.8.
Agent activity
3 hits · last 30 days
node
2
Resources
mkdocs-minify-plugin — pip install mkdocs-minify-plugin · libregistry