A powerful HTML whitespace remover
Project description
HTML Whitespace remover for Django
Introduction :
A powerful tool to optimize HTML
Why use “django_stip_whitespace” ?
Adds line break to InlineJS.
It can automagically minify inline CSS, JS.
Removes <!–prettier-ignore–> from HTML.
It speeds up website by reducing the HTML size.
Can be used with ‘django.middleware.gzip.GZipMiddleware’.
Its mostly based on C ( gzip ) and Rust ( minify-html ) libraries.
Is very customizable. ( You can configure lower level minify-html rust bindings from settings.py )
Significantly lower bytes transferred when working with frameworks like AlpineJs ( Almost fully working & Please open a issue in the Issue Tracker if you encounter any bug) & Petite Vue.
Why souldn’t you use django_stip_whitespace ?
Adds unnecessary ‘;;’ in HTML. ( If you know any regex to fix this please put a pull request )
Although I tried my best to use Compiled Language for Optimizations. It can still be sub miliseconds ( > 0.001 ) slower compared to normal Django Rendering. ( If you know any way to improve performance, please put a pull request )
Requirements :
minify-html
Django > 3 ( Should work with version 2? )
Python 3 ( Should work with all version? )
Brotli ( or BrotliPy ) | ( Optional )
ZSTD ( Optional )
User guide :
Installation :
Install with pip from pypi:
$ python -m pip install django_strip_whitespace
Install with pip from github ( Development | Not Recommended for Production ):
$ python -m pip install https://codeload.github.com/baseplate-admin/django_strip_whitespace/zip/refs/heads/main
Then include it in your django project:
MIDDLEWARE = [ ... "strip_whitespace.middlewares.HtmlStripWhiteSpaceMiddleware.html_strip_whitespace", ]
Or if you like:
MIDDLEWARE += "strip_whitespace.middlewares.HtmlStripWhiteSpaceMiddleware.html_strip_whitespace"
Change Lower Level Bindings :
The module allows settings to be changed from Django’s settings.py file. If you would like to change any settings, refer to minify-html’s source code.
The bindings are ( by default set to True):
STRIP_WHITESPACE_DO_NOT_MINIFY_DOCTYPE, # passes do_not_minify_doctype to minify-html STRIP_WHITESPACE_ENSURE_SPEC_CONPLIANT_UNQUOTED_ATTRIBUTE_VALUES, # passes ensure_spec_compliant_unquoted_attribute_values to minify-html STRIP_WHITESPACE_KEEP_CLOSING_TAGS, # passes keep_closing_tags to minify-html STRIP_WHITESPACE_KEEP_COMMENTS, # passes keep_comments to minify-html STRIP_WHITESPACE_KEEP_HTML_AND_HEAD_OPENING_TAGS, # passes keep_html_and_head_opening_tags to minify-html STRIP_WHITESPACE_KEEP_SPACES_BETWEEN_ATTRIBUTES, # passes keep_spaces_between_attributes to minify-html STRIP_WHITESPACE_MINIFY_CSS, # passes minify_css to minify-html STRIP_WHITESPACE_MINIFY_JS, # passes minify_js to minify-html STRIP_WHITESPACE_REMOVE_BANGS, # passes remove_bangs to minify-html STRIP_WHITESPACE_REMOVE_PROCESSING_INSTRUCTIONS, # passes remove_processing_instructions to minify-html
If you would like to change any of the above variables, simply put them in settings.py. Please note that every variable here is a python boolean.
For example:
# settings.py STRIP_WHITESPACE_DO_NOT_MINIFY_DOCTYPE = False
Contributing :
If you like this project add a star. If you have problems or suggestions please put them in the Issue Tracker. If you like to add features. Fork this repo and submit a Pull Request. 😛
Roadmap :
You tell me. If i have free time, I will implement it.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for django_strip_whitespace-0.0.20-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea4e7cd5b6d3c497828a85cd08c69c977847ac89e1ab2207686e87dc3d0a4981 |
|
MD5 | 157b758a3f1a29690cef2c1d4f89bc03 |
|
BLAKE2b-256 | a1e662b6bbd947dccda645f91ed469ef854115c29f72ad6e5c4deb5b5cb283ec |