An MkDocs plugin to minify HTML, JS or CSS files prior to being written to disk.
HTML minification is done using htmlmin.
JS minification is done using jsmin.
CSS minification is done using csscompressor.
Install the plugin using pip:
pip install mkdocs-minify-plugin
Activate the plugin in mkdocs.yml
:
plugins:
- search
- minify:
minify_html: true
minify_js: true
minify_css: true
htmlmin_opts:
remove_comments: true
js_files:
- my/javascript/dir/file1.js
- my/javascript/dir/file2.js
css_files:
- my/css/dir/file1.css
- my/css/dir/file2.css
Note: If you have no
plugins
entry in your config file yet, you'll likely also want to add thesearch
plugin. MkDocs enables it by default if there is noplugins
entry set, but now you have to enable it explicitly.
minify_html
: Sets whether HTML files should be minified. Defaults tofalse
.htmlmin_opts
: Sets runtime htmlmin API options using the config parameters of htmlminminify_js
: Sets whether JS files should be minified. Defaults tofalse
. If set totrue
, you must specificy the JS to be minified files usingjs_files
(see below).minify_css
: Sets whether CSS files should be minified. Defaults tofalse
. If set totrue
, you must specificy the CSS to be minified files usingcss_files
(see below).js_files
: List of JS files to be minified. The plugin will generate minified versions of these files and save them as.min.js
in the output directory.css_files
: List of CSS files to be minified. The plugin will generate minified versions of these files and save them as.min.css
in the output directory.
Note: When using
minify_jss
orminify_css
, you don't have to modify theextra_javascript
orextra_css
entries in yourmkdocs.yml
file. The plugins automatically takes care of that.
More information about plugins in the MkDocs documentation.
More information about templates here.
More information about blocks here.