Course contentsShow
← JavaScript
Lesson 1210 of 2,72327. The Event LoopFree lesson

setTimeout in Background Tabs

Understand how browsers aggressively throttle setTimeout in inactive tabs to save resources.

setTimeout in Background Tabs

What you'll learn: How browsers throttle setTimeout when your tab isn't active, and why this matters for your code.

The Browser's Resource-Saving Trick

When you switch to a different browser tab, the tab you left behind becomes "inactive" or "backgrounded." To save CPU cycles and battery life, browsers aggressively throttle setTimeout calls in inactive tabs—meaning your timers run much less frequently than you requested.

Modern browsers (Chrome, Firefox, Safari, Edge) typically enforce a minimum delay of 1000ms (1 second) for setTimeout in background tabs, regardless of what delay you specified. Even if you write setTimeout(fn, 100), the browser may wait a full second or longer before executing it.

Why This Matters

If your code relies on precise timing—like animations, real-time dashboards, polling intervals, or countdown timers—it will behave differently when the tab isn't visible. Your 100ms animation frame might suddenly become a 1000ms+ delay, causing jerky behavior when users return to the tab.

// This might run every ~100ms when tab is active
// but only every ~1000ms+ when backgrounded
setTimeout(() => {
  console.log('Update UI');
}, 100);

What You Can Do

You can't override browser throttling, but you can:

  • Use the Page Visibility API to detect when your tab becomes hidden and pause timers accordingly
  • Design your code to handle variable delays gracefully
  • Consider that background tabs are intentionally deprioritized

Key Takeaway: Browsers throttle setTimeout to at least 1 second in inactive tabs to conserve resources—your timers won't run as frequently as specified when users aren't looking at your page.