All Topics
All Topics
Technology
Technology
Design
Design
Programming
Programming
Science
Science
News
News
Gaming
Gaming
Entertainment
Entertainment
Business
Business
Finance
Finance
Sports
Sports
Health
Health
Food
Food
Travel
Travel
Art
Art
Music
Music
Books
Books
Education
Education
Politics
Politics
Personal
Personal
No algorithm. No AI slop. No ads. Just RSS. Pro-human. Indie writers. Real journalism. Open web. Chronological. Hand toasted.

Browser JavaScript Timer Throttling: Why setTimeout(0) Actually Delays 4ms

By

vidyesh

8mo ago· 6 min readenInsight

Summary

This article explains how browsers implement a 4ms minimum delay for JavaScript setTimeout(0) calls, rather than executing them immediately. The author, who worked on the Microsoft Edge team, reveals this is a deliberate browser design choice to prevent websites from abusing timers and draining user battery life or blocking interactivity through excessive setTimeout spamming.

Key quotes

· 3 pulled
setTimeout(0) is not really setTimeout(0). Instead, it could run 4 milliseconds later
browsers did this to avoid "abuse". I.e. there are a lot of websites out there that spam setTimeout
to avoid draining the user's battery or blocking interactivity, browsers set a special "clamped" minimum of 4ms
Snippet from the RSS feed
Even if you’ve been doing JavaScript for a while, you might be surprised to learn that setTimeout(0) is not really setTimeout(0). Instead, it could run 4 milliseconds later: Nearly a decade a…

You might also wanna read