Performance: Serving CSS files
HIGH IMPACT
This affects page load speed by controlling how quickly CSS files are delivered and applied, impacting the Largest Contentful Paint (LCP).
from flask import Flask app = Flask(__name__) # Use Flask's built-in static file serving # Place CSS in 'static/style.css' # In HTML: <link rel="stylesheet" href="/static/style.css">
from flask import Flask app = Flask(__name__) @app.route('/style.css') def style(): with open('static/style.css') as f: return f.read(), 200, {'Content-Type': 'text/css'}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Serving CSS via Flask route reading file each time | N/A | N/A | Blocks rendering until CSS loads | [X] Bad |
| Serving CSS via Flask static folder with caching | N/A | N/A | Fast style application, minimal blocking | [OK] Good |