Is there a Flask or Jinja2 configuration flag / extension to automatically minify the HTML output after rendering the template?
Modifying @Bletch answer for the latest version of htmlmin.
from flask import Flask
import htmlmin
app = Flask(__name__)
@app.route('/')
def home():
rendered_html = render_template('home.html')
return htmlmin.minify(rendered_html)
https://htmlmin.readthedocs.io/en/latest/quickstart.html
The minified html will still have some spaces between the tags. If we want to remove that, then remove_empty_space =True
attribute needs to be added while the template is rendered.
return htmlmin.minify(rendered_html, remove_empty_space =True)
https://htmlmin.readthedocs.io/en/latest/reference.html