Get the latest tech news

Why do browsers throttle JavaScript timers?


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…

I didn’t test every possible combination of 1) battery vs plugged in, 2) monitor refresh rates, 3) background vs foreground tabs, etc., even though I know all of these things can affect the clamping. Although Todd sees the API more as a compromise between the two groups: yes, it offers a lot of control, but it also aligns with the browser’s actual rendering pipeline rather than random timeouts. For the time being, I’ll just do what most web devs do: choose whatever API accomplishes my goals today, and hope that browsers don’t change too much in the future.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of javascript

javascript

Photo of browsers

browsers

Photo of JavaScript timers

JavaScript timers

Related news:

News photo

Checking if a JavaScript native function is monkey patched (2022)

News photo

Show HN: Pbar.io – Distributed progress bars that work in terminals and browsers

News photo

Show HN: Ion, a Rust/Tokio powered JavaScript runtime for embedders