Skip to content

[Performance]: Leaderboard polls every 2 minutes even when browser tab is hidden #172

@5hivam123

Description

@5hivam123

⚡ Performance Issue

The leaderboard runs a setInterval that fetches all data every 2 minutes regardless of whether the tab is visible or not — wasting bandwidth and API calls when the user has switched to another tab.

📍 Location

leaderboard.html — inline <script>

setInterval(fetchLeaderboardData, 2 * 60 * 1000);

✅ Fix

Use the Page Visibility API to pause polling when tab is hidden:

document.addEventListener('visibilitychange', () => {
  if (document.visibilityState === 'visible') {
    fetchLeaderboardData();
    startPolling();
  } else {
    stopPolling();
  }
});

let pollInterval;
function startPolling() {
  pollInterval = setInterval(fetchLeaderboardData, 2 * 60 * 1000);
}
function stopPolling() {
  clearInterval(pollInterval);
}
startPolling();

📁 File

leaderboard.html

🏷️ Labels

performance level:intermediate

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions