flask extension to minify html, css, js and less
Project description
flask_minify
A Flask extension to minify flask response for html, javascript, css and less compilation as well.
Install:
- With pip
pip install Flask-Minify
- From the source:
git clone https://github.com/mrf345/flask_minify.git
cd flask_minify
python setup.py install
Setup:
- Inside Flask app:
from flask import Flask
from flask_minify import minify
app = Flask(__name__)
minify(app=app)
- Result:
Before:
<html>
<head>
<script>
if (true) {
console.log('working !')
}
</script>
<style>
body {
background-color: red;
}
</style>
</head>
<body>
<h1>Flask-Less Example !</h1>
</body>
</html>
After:
<html> <head><script>if(true){console.log('working !')}</script><style>body{background-color:red;}</style></head> <body> <h1>Flask-Less Example !</h1> </body> </html>
Options:
def __init__(
self, app=None, html=True, js=True, cssless=True,
fail_safe=True, bypass=[], bypass_caching=[], caching_limit=1
):
''' Flask extension to minify flask response for html, javascript,
css and less.
Parameters:
----------
app: Flask app instance to be passed.
js: To minify the css output.
cssless: To minify spaces in css.
cache: To cache minifed response with hash.
fail_safe: to avoid raising error while minifying.
bypass: list of endpoints to bypass minifying for. (Regex)
bypass_caching: list of endpoints to bypass caching for. (Regex)
caching_limit: to limit the number of minifed response variations.
NOTE: if `caching_limit` is set to 0, we'll not cache any endpoint
response, so if you want to disable caching just do that.
EXAMPLE: endpoint is the name of the function decorated with the
`@app.route()` so in the following example the endpoint
will be `root`:
@app.('/root/<id>')
def root(id):
return id
NOTE: when using a `Blueprint` the decorated endpoint will be
suffixed with the blueprint name;
`Blueprint('blueprint_name')` so here the endpoint will be
`blueprint_name.root`.
`bypass` and `bypass_caching` can handle regex patterns so if
you want to bypass all routes on a certain blueprint you can
just pass the pattern as such:
minify(app, bypass=['blueprint_name.*'])
'''
Credit:
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
Flask-Minify-0.16.tar.gz
(4.9 kB
view hashes)
Built Distribution
Close
Hashes for Flask_Minify-0.16-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06421bf48a452da9aa3201e65b4ef86354b61aba5bc2f412456a46007dc4be37 |
|
MD5 | 09826e5c6632e823a9bb9dab4d5e1435 |
|
BLAKE2b-256 | 5042cdc93a3deae235764b96bd158d1aa5150860aaacb4706ef9ffd06a3f5b96 |