Performance: Serving images
HIGH IMPACT
This affects page load speed by controlling how quickly images appear and how much data the browser downloads.
from flask import Flask, send_from_directory app = Flask(__name__) @app.route('/image') def image(): response = send_from_directory('static', 'optimized_image.webp') response.cache_control.max_age = 86400 # cache for 1 day return response
from flask import Flask, send_file app = Flask(__name__) @app.route('/image') def image(): return send_file('static/large_image.png')
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Serving large uncompressed images | Minimal | 0 | High decode and paint cost | [X] Bad |
| Serving optimized compressed images with caching | Minimal | 0 | Low decode and paint cost | [OK] Good |