html minify for django
Project description
html minify for django
Why minify HTML code?
One of important points on client side optimization is minify HTML, with minified HTML code, you reduce the size of data transferred from your server to your client, and your pages load faster.
Installing
For install django-htmlmin, run on terminal:
$ [sudo] pip install django-htmlmin
Using the midleware
All you need to do is add htmlmin.middleware.HtmlMinifyMiddleware to your MIDDLEWARE_CLASSES:
MIDDLEWARE_CLASSES = ( # other middleware classes 'htmlmin.middleware.HtmlMinifyMiddleware', )
Using the html_minify function
If you are not working with Django, you can invoke the html_minify function manually:
from htmlmin.minify import html_minify html = '<html> <body>Hello world</body> </html>' minified_html = html_minify(html)
Here is an example of Flask view:
from flask import Flask from htmlmin.minify import html_minify app = Flask(__name__) @app.route('/') def home(): rendered_html = render_template('home.html') return html_minify(rendered_html)
Keeping comments
By default, html_minify function removes all comments. If you want to keep them, you can pass False as value to ignore_comments parameter on that function:
from htmlmin.minify import html_minify html = '<html> <body>Hello world<!-- comment to keep --></body> </html>' minified_html = html_minify(html, ignore_comments=False)
development
Source hosted at GitHub
Report issues on GitHub Issues
Pull requests are very welcomed! Make sure your patches are well tested.
running the tests
if you are using a virtualenv, all you need is:
$ make test
community
irc channel
#cobrateam channel on irc.freenode.net
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 Distribution
File details
Details for the file django-htmlmin-0.1.tar.gz
.
File metadata
- Download URL: django-htmlmin-0.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f9e0a0cef078768d153800a09688869b13a2cad4b2e39d38f34c12deb37b39c |
|
MD5 | 38ad3019acb9c7ee57f86f14f78ffe66 |
|
BLAKE2b-256 | 60a545f520f36ccfff75f654b0f88721da559a18f80565511189e37631840450 |