requestIdleCallback

This article needs a technical review. How you can help.

 

Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

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-fist-out order unless the function's timeout is reached before the browser calls it.

Syntax

var handle = Window.requestIdleCallback(callback[, options])

Returns

An unsigned long integer that can be used to cancel the callback using the Window.cancelIdleCallback() method.

Parameters

callback
A reference to a function that should be called in the near future. The callback function takes a deadline argument with the following properties:
  • timeRemaining: A reference to a method that returns a DOMHighResTimeStamp.
  • didTimeout: A boolean that returns false if the callback was invoked by the user agent during idle, and true otherwise (e.g. if a timeout option was given and expired before there was sufficient idle time).
options Optional
Contains optional configuration parameters. It has the following property:
  • timeout: A deadline by which the browser must call the given callback function. This value is given in milliseconds.

Specifications

Specification Status Comment
Cooperative Scheduling of Background Tasks Editor's Draft Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 47 ? ? ? ?
Feature Android Android Webview Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support No support 47 ? ? ? ? ? 47

Document Tags and Contributors

 Contributors to this page: jpmedley, Krinkle, rolfedh
 Last updated by: jpmedley,