Performance: Long polling as fallback
MEDIUM IMPACT
This affects the responsiveness and load on the server and client during real-time data updates when WebSocket is unavailable.
app.get('/updates', (req, res) => { const checkForUpdates = () => { if (dataAvailable()) { res.json({ data: getData() }); } else { setTimeout(checkForUpdates, 1000); // retry after 1 second } }; checkForUpdates(); });
app.get('/updates', (req, res) => { setTimeout(() => { res.json({ data: 'new data' }); }, 10000); // waits 10 seconds before responding });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Naive long polling with fixed delay | Minimal DOM changes | 0 reflows triggered by polling itself | Delayed paint due to waiting on response | [X] Bad |
| Conditional long polling with data check | Minimal DOM changes | 0 reflows triggered by polling itself | Faster paint when data is ready | [OK] Good |