DeveloperBreeze

Tutorials Programming Tutorials, Guides & Best Practices

Explore 149+ expertly crafted tutorials tutorials, components, and code examples. Stay productive and build faster with proven implementation strategies and design patterns from DeveloperBreeze.

Optimizing HTML Delivery in Flask with Minification and Compression

Tutorial August 20, 2024
python

from flask import current_app
from htmlmin import minify

@app.after_request
def after_request(response):
    if response.content_type == 'text/html; charset=utf-8' and not current_app.debug:
        response.set_data(minify(response.get_data(as_text=True)))
    return response

Explanation: