Why do browsers clamp setTimeout delays?
For performance (prevent flooding the event loop with zero-delay timers), battery (background tabs do not need precise timers), and security (prevent timing attacks and excessive resource use).
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in setTimeout Minimum Delay and Clamping in JavaScript
After 5 nested levels, browsers enforce a 4ms minimum. This is specified in the HTML spec to prevent abuse. The first 5 levels can use 0ms, but after that, the delay is clamped to 4ms.
Yes. To save battery, browsers throttle timers in background tabs. Chrome and Firefox enforce a minimum of about 1 second for setTimeout in background tabs. Very long-backgrounded tabs may be throttled even more.
Measure the actual delay with Date.now() or performance.now(). Compare the expected delay to the actual delay. If the actual delay is much larger, the timer is being throttled (likely in a background tab).
Still have questions?
Browse all our FAQs or reach out to our support team
