HTML minifier for Python frameworks (not only Django, despite the name)
django-html is an HTML minifier for Python, with full support for HTML 5. It supports Django, Flask and many other Python web frameworks. It also provides a command line tool, that can be used for static websites or deployment scripts.
Why minify HTML code?
One of the important points on client side optimization is to minify HTML. With minified HTML code, you reduce the size of the data transferred from the server to the client, which results in faster load times.
Installing
To install django-htmlmin, run this on the terminal: :
$ [sudo] pip install django-htmlmin
Using the middleware
All you need to do is add two middlewares to your MIDDLEWARE_CLASSES
and enable the HTML_MINIFY
setting:
MIDDLEWARE_CLASSES = (
# other middleware classes
'htmlmin.middleware.HtmlMinifyMiddleware',
'htmlmin.middleware.MarkRequestMiddleware',
)
Note that if you’re using Django’s caching