项目作者: hamidfzm

项目描述 :
Flask html response minifier
高级语言: Python
项目地址: git://github.com/hamidfzm/Flask-HTMLmin.git
创建时间: 2015-02-12T09:25:14Z
项目社区:https://github.com/hamidfzm/Flask-HTMLmin

开源协议:BSD 3-Clause "New" or "Revised" License

下载


Flask-HTMLmin

PyPI version
Supported Python Versions
License
tests
codecov

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:

  1. pip install Flask-HTMLmin

Or use pipenv:

  1. pipenv install Flask-HTMLmin

Or use poetry:

  1. poetry add Flask-HTMLmin

Or alternatively, you can download the repository and install it manually by doing:

  1. git clone git@github.com:hamidfzm/Flask-HTMLmin.git
  2. cd Flask-HTMLmin
  3. python setup.py install

Example

  1. from flask import Flask, render_template
  2. from flask_htmlmin import HTMLMIN
  3. app = Flask(__name__)
  4. app.config['MINIFY_HTML'] = True
  5. htmlmin = HTMLMIN(app)
  6. # or you can use HTMLMIN().init_app(app)
  7. # pass additional parameters to htmlmin
  8. # HTMLMIN(app, **kwargs)
  9. # example:
  10. # htmlmin = HTMLMIN(app, remove_comments=False, remove_empty_space=True, disable_css_min=True)
  11. @app.route('/')
  12. def main():
  13. # index.html will be minimized !!!
  14. return render_template('index.html')
  15. @app.route('/exempt')
  16. @htmlmin.exempt
  17. def exempted_route():
  18. # index.html will be exempted and not blessed by holy htmlmin !!!
  19. return render_template('index.html')
  20. if __name__ == '__main__':
  21. app.run()

TODO

  • Test cases
  • Route (or URL rule) exemption
  • Caching (in progress)
  • Minify inline CSS
  • Minify inline Javascript
  • Type hints