Наши волонтёры ещё не перевели данную статью на Русский. Присоединяйтесь к нам и помогите сделать эту работу!
Вы можете также прочитать эту статью на English (US).
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.
timeoutoption is strongly recommended for required work, as otherwise it's possible multiple seconds will elapse before the callback is fired.
var handle = 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 a
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, the timeout will be called during the next idle period, even if doing so risks causing a negative performance impact.
|Cooperative Scheduling of Background Tasks||Candidate Recommendation||Initial definition.|
|Feature||Chrome||Firefox (Gecko)||Internet Explorer||Opera||Safari (WebKit)|
|Basic support||47||53 (53) ||No support||34||No support|
|Feature||Android Webview||Chrome for Android||Firefox Mobile (Gecko)||Firefox OS||IE Mobile||Opera Mobile||Safari Mobile|
|Basic support||47||47||53.0 (53) ||?||?||?||?|
requestIdleCallback() is implemented in Firefox 53 but is disabled by default; to enable it, set the preference
true. It is enabled by default starting in Firefox 55.