This template demonstrates intelligent polling systems for real-time data updates including adaptive intervals, performance optimization, and multiple real-time technologies (polling, WebSockets, Server-Sent Events).
File: polling-manager.jsLocation: executePoll() method after data fetch
Current State: Intervals are fixed regardless of data changes
Your Task: Implement dynamic interval adjustment:
Detect if data changed using hash comparison
Increase frequency (shorter interval) when data changes often
Decrease frequency (longer interval) when data is stable
Stay within adaptiveRange bounds
Success Criteria:
Rapidly changing data (crypto prices) polls faster
Stable data (Pokemon stats) polls slower
Intervals stay within configured ranges
Dashboard shows adaptive interval changes
Hints:
Compare poller.lastDataHash with new data hash
Track change frequency over last 5 polls
Adjust poller.adaptiveInterval by +/-20% per change detection
File: polling-manager.jsLocation: setupGlobalHandlers() and shouldPoll() methods
Current State: Battery API is detected but polling continues regardless
Your Task: Reduce polling when battery is low:
Get battery level using Battery Status API
When ``battery < 20``%, multiply all intervals by 3x
When ``battery < 10``%, pause all low-priority pollers
Resume normal polling when charging or ``battery > 20``%
File: polling-manager.jsLocation: executePoll() error handler
Current State: Errors are logged but polling continues at same rate
Your Task: Implement exponential backoff on failures:
Track consecutive errors in poller.errorCount
Double the interval after each failure (up to 5x original)
Reset interval after successful request
Stop polling after 5 consecutive failures
Success Criteria:
Failed requests trigger longer delays
Interval doubles with each failure (1x -> 2x -> 4x -> 8x)
File: dashboard.jsLocation: updateDataDisplay() method
Current State: Old data displays without warning
Your Task: Add visual indicators for stale data:
Calculate time since last successful update
Show yellow warning if ``data > 2``x polling interval old
Show red error if ``data > 5``x polling interval old
Display "Last updated: X seconds ago" tooltip
Success Criteria:
Fresh data has no indicator (green/normal)
Stale data (>2x interval) shows yellow warning badge
Very stale data (>5x interval) shows red error badge