Hasty Briefsbeta

Why do browsers throttle JavaScript timers?

9 days ago
  • #JavaScript
  • #Browser APIs
  • #Web Performance
  • setTimeout(0) actually has a minimum delay of 4ms due to browser throttling to prevent abuse.
  • Browsers introduced throttling to avoid battery drain and maintain interactivity, with variations like 16ms for battery-powered devices or 1s for background tabs.
  • Newer APIs like scheduler.postTask offer better performance with minimal delay compared to setTimeout.
  • Different browsers show varying performance for setTimeout alternatives: Chrome and Firefox clamp to ~4ms, while Safari throttles more aggressively (~26ms).
  • The debate around timer throttling centers on balancing developer control with user experience, leading to APIs like scheduler.postTask that offer more granular control.
  • Legacy concerns and web compatibility play a role in maintaining setTimeout throttling, while newer APIs aim to provide better alternatives without breaking existing sites.