DeveloperBreeze

Static Files Development Tutorials, Guides & Insights

Unlock 1+ expert-curated static files tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your static files skills on DeveloperBreeze.

Optimizing HTML Delivery in Flask with Minification and Compression

Tutorial August 20, 2024
python

@app.after_request
def after_request(response):
    if response.content_type == 'text/html; charset=utf-8':
        response.set_data(minify(response.get_data(as_text=True)))
        response.headers['Cache-Control'] = 'public, max-age=3600'
    return response
  • Cache-Control: public, max-age=3600: Instructs the browser to cache the HTML content for 3600 seconds (1 hour), reducing the number of requests made to the server.