Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Window: requestIdleCallback() method

Limited availability

Thewindow.requestIdleCallback() method queues a functionto be called during a browser's idle periods. This enables developers to performbackground and low priority work on the main thread, without impactinglatency-critical events such as animation and input response. Functions are generallycalled in first-in-first-out order; however, callbacks which have atimeoutspecified may be called out-of-order if necessary in order to run them before thetimeout elapses.

You can callrequestIdleCallback() within an idle callback function toschedule another callback to take place no sooner than the next pass through the eventloop.

Note:Atimeout option is strongly recommended for required work,as otherwise it's possible multiple seconds will elapse before the callback is fired.

Syntax

js
requestIdleCallback(callback)requestIdleCallback(callback, options)

Parameters

callback

A reference to a function that should be called in the near future, when the eventloop is idle. The callback function is passed anIdleDeadline objectdescribing the amount of time available and whether or not the callback has been runbecause the timeout period expired.

optionsOptional

Contains optional configuration parameters. Currently only one property is defined:

timeout

If the number of milliseconds represented by this parameter has elapsed and the callback has not already been called, then a task to execute the callback is queued in the event loop (even if doing so risks causing a negative performance impact).timeout must be a positive value or it is ignored.

Return value

An ID which can be used to cancel the callback by passing it into thewindow.cancelIdleCallback() method.

Examples

Specifications

Specification
requestIdleCallback()
# the-requestidlecallback-method

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp