Performance: Why static file serving matters
HIGH IMPACT
This affects how quickly the browser can load images, stylesheets, and scripts, impacting page load speed and user experience.
from flask import Flask app = Flask(__name__, static_folder='static') # Flask automatically serves files from /static URL path # Access CSS at /static/style.css directly
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 |
|---|---|---|---|---|
| Manual file read in route | 0 (no DOM changes) | 0 | High due to delayed resource load | [X] Bad |
| Flask static folder serving | 0 | 0 | Low due to fast resource delivery | [OK] Good |