Performance: Why real-time matters
Real-time features impact how quickly users see updates and interact with the page, affecting responsiveness and perceived speed.
Use WebSocket connections or Server-Sent Events to push only changed data to the client, updating DOM elements selectively.Use frequent full page reloads or polling every second with Flask routes returning full HTML pages.
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full page reload polling | High (entire DOM replaced) | Multiple per reload | High (full repaint) | [X] Bad |
| WebSocket partial updates | Low (targeted nodes only) | Single per update | Low (partial repaint) | [OK] Good |
from flask_socketio import SocketIO, send
socketio = SocketIO(app)
@socketio.on('message')
def handle_message(msg):
send(f'Received: {msg}', broadcast=True)from flask_socketio import SocketIO, emit
socketio = SocketIO(app)
@socketio.on('connect')
def on_connect():
emit('update', {'data': 'Welcome!'})
if __name__ == '__main__':
app.run()Pass the test and this pattern moves unknown