Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hamidfzm/flask-htmlmin
Flask HTML response minifier
https://github.com/hamidfzm/flask-htmlmin
flask flask-extensions flask-htmlmin htmlmin minify minify-html python
Last synced: 2 days ago
JSON representation
Flask HTML response minifier
- Host: GitHub
- URL: https://github.com/hamidfzm/flask-htmlmin
- Owner: hamidfzm
- License: bsd-3-clause
- Created: 2015-02-12T09:25:14.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2025-01-03T22:46:45.000Z (2 days ago)
- Last Synced: 2025-01-03T23:23:13.327Z (2 days ago)
- Topics: flask, flask-extensions, flask-htmlmin, htmlmin, minify, minify-html, python
- Language: Python
- Homepage:
- Size: 148 KB
- Stars: 96
- Watchers: 6
- Forks: 25
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Flask-HTMLmin
=============
[![PyPI version](https://badge.fury.io/py/Flask-HTMLmin.svg)](https://badge.fury.io/py/Flask-HTMLmin)
![Supported Python Versions](https://img.shields.io/badge/python-3.6%20%7C%203.7%20%7C%203.8%20%7C%203.9-blue.svg)
[![License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](LICENSE)
![tests](https://github.com/hamidfzm/Flask-HTMLmin/workflows/tests/badge.svg)
[![codecov](https://codecov.io/gh/hamidfzm/Flask-HTMLmin/branch/master/graph/badge.svg)](https://codecov.io/gh/hamidfzm/Flask-HTMLmin)Minify flask `text/html` mime type responses.
Just add `MINIFY_HTML = True` to your deployment config to minify HTML and text responses of your flask application.Installation
------------
To install Flask-HTMLmin, simply use pip:pip install Flask-HTMLmin
Or use pipenv:
pipenv install Flask-HTMLmin
Or use poetry:
poetry add Flask-HTMLmin
Or alternatively, you can download the repository and install it manually by doing:
git clone [email protected]:hamidfzm/Flask-HTMLmin.git
cd Flask-HTMLmin
python setup.py installExample
-------
```python
from flask import Flask, render_template
from flask_htmlmin import HTMLMIN
app = Flask(__name__)
app.config['MINIFY_HTML'] = Truehtmlmin = HTMLMIN(app)
# or you can use HTMLMIN().init_app(app)
# pass additional parameters to htmlmin
# HTMLMIN(app, **kwargs)
# example:
# htmlmin = HTMLMIN(app, remove_comments=False, remove_empty_space=True, disable_css_min=True)@app.route('/')
def main():
# index.html will be minimized !!!
return render_template('index.html')@app.route('/exempt')
@htmlmin.exempt
def exempted_route():
# index.html will be exempted and not blessed by holy htmlmin !!!
return render_template('index.html')if __name__ == '__main__':
app.run()
```TODO
----
- [x] Test cases
- [x] Route (or URL rule) exemption
- [x] Caching (in progress)
- [x] Minify inline CSS
- [ ] Minify inline Javascript
- [ ] Type hints