Performance: Polling as fallback
MEDIUM IMPACT
Polling as fallback affects how quickly the page updates with new data and impacts server load and client rendering frequency.
import time from flask import Flask, jsonify app = Flask(__name__) last_value = None @app.route('/data') def data(): global last_value current = time.time() if last_value is None or current - last_value > 5: last_value = current return jsonify({'value': current}) else: return jsonify({'value': None}) # No update
import time from flask import Flask, jsonify app = Flask(__name__) @app.route('/data') def data(): # Client polls every 1 second return jsonify({'value': time.time()})
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Frequent polling every 1s | High (many updates) | High (many reflows) | High (many paints) | [X] Bad |
| Conditional polling every 5s or on change | Low (few updates) | Low (few reflows) | Low (few paints) | [OK] Good |