Skip to main content

An MkDocs plugin to minify HTML, JS or CSS files prior to being written to disk

Project description

mkdocs-minify-plugin

PyPI - Python Version

An MkDocs plugin to minify HTML, JS or CSS files prior to being written to disk.

HTML minification is done using htmlmin2.

JS minification is done using jsmin.

CSS minification is done using csscompressor.

Setup

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
      cache_safe: 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 the search plugin. MkDocs enables it by default if there is no plugins entry set, but now you have to enable it explicitly.

Options

  • minify_html:
    • Defaults to False.
    • Sets whether HTML files should be minified.
  • minify_js:
    • Defaults to False.
    • Sets whether JS files should be minified.
      If set to True, you must specify the JS to be minified files using js_files (see below).
  • minify_css:
    • Defaults to False.
    • Sets whether CSS files should be minified.
      If set to True, you must specify the CSS to be minified files using css_files (see below).
  • htmlmin_opts:
  • cache_safe:
    • Defaults to False.
    • Sets whether a hash should be added to the JS and CSS file names. This ensures that the browser always loads the latest version of the files instead of loading them from the cache.
      If set to True, you must specify the files using js_files or css_files (see below).
  • js_files:
    • Defaults to None.
    • 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:
    • Defaults to None.
    • 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_js or minify_css, you don't have to modify the extra_javascript or extra_css entries in your mkdocs.yml file. The plugins automatically takes care of that.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mkdocs-minify-plugin-0.7.2.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mkdocs_minify_plugin-0.7.2-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs-minify-plugin-0.7.2.tar.gz.

File metadata

  • Download URL: mkdocs-minify-plugin-0.7.2.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for mkdocs-minify-plugin-0.7.2.tar.gz
Algorithm Hash digest
SHA256 6a551e22d6517eaef9e1890afd60021dc1dcd1255de02d266f588d1ace040713
MD5 64b8acd4069294ffe49b0e20ab67c5f5
BLAKE2b-256 46e7417d1f8a59a04d30dcbc5458f11f119a18630b627d17ffbb546e9d9f9897

See more details on using hashes here.

File details

Details for the file mkdocs_minify_plugin-0.7.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mkdocs_minify_plugin-0.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ae8bfc4a68806883e990ea025938b3f989da7b9fa08ea8390dba47adf25e0c5b
MD5 a41eaa3c453cd96dcbb88557d0969729
BLAKE2b-256 8b086c1a5a558970d1c4d31780c2072cae1f9410ba549ea8788da96767c3452d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page