requestIdleCallback: Idle-Time Work

Dina fills the prize envelopes in idle time: a real requestIdleCallback, timeRemaining() and didTimeout read from its deadline, with the field still, racing…

Why it matters

Work that is not urgent (sending analytics, preparing data, filling a cache) should never take time from clicks and frames. An idle callback puts it in breaks that are really empty, as long as you respect the deadline and give a timeout when the work must get done.

The key idea

Idle time is given by the browser, not promised

Common mistakes

Try it in this playground