window.requestIdleCallback() method queues a function
to be called during a browser's idle periods. This enables developers to perform
background and low priority work on the main event loop, without impacting
latency-critical events such as animation and input response. Functions are generally
called in first-in-first-out order; however, callbacks which have a
specified may be called out-of-order if necessary in order to run them before the
You can call
requestIdleCallback() within an idle callback function to
schedule another callback to take place no sooner than the next pass through the event
timeoutoption is strongly recommended for required work, as otherwise it's possible multiple seconds will elapse before the callback is fired.
window.requestIdleCallback(callback); window.requestIdleCallback(callback, options);
An ID which can be used to cancel the callback by passing it into the
- A reference to a function that should be called in the near future, when the event
loop is idle. The callback function is passed an
IdleDeadlineobject describing the amount of time available and whether or not the callback has been run because the timeout period expired.
- Contains optional configuration parameters. Currently only one property is defined:
timeoutis specified and has a positive value, and the callback has not already been called by the time timeout milliseconds have passed, a task to execute the callback is queued in the event loop, even if doing so risks causing a negative performance impact.
|Cooperative Scheduling of Background Tasks |
BCD tables only load in the browser