This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.
The 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 timeout
specified may be called out-of-order if necessary in order to run them before the timeout elapses.
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 loop.
var handle = Window.requestIdleCallback(callback[, options])
An ID which can be used to cancel the callback by passing it into the Window.cancelIdleCallback()
method.
callback
IdleDeadline
object describing the amount of time available and whether or not the callback has been run because the timeout period expired.options
Optional
timeout
: If timeout
is specified and has a positive value, and the callback has not already been called by the time timeout milliseconds have passed, the timeout will be called during the next idle period, even if doing so risks causing a negative performance impact..See our complete example in the article Cooperative Scheduling of Background Tasks API.
Specification | Status | Comment |
---|---|---|
Cooperative Scheduling of Background Tasks | Working Draft | Initial definition. |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 47 | 52 (52) | No support | 34 | No support |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | No support | 47 | 52.0 (52) | ? | ? | ? | ? | 47 |
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/window/requestIdleCallback