whenIdle
Runs callback when the browser is idle, with requestIdleCallback, for work that can wait
(prefetching, analytics, warming a cache).
Where requestIdleCallback does not exist (Safari, Node.js), it falls back to setTimeout,
so the callback still runs, after the current task.
Available since v3.1.5
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
callback | function | The work to run |
options | WhenIdleOptions | Timeout and cancellation — see WhenIdleOptions |
Returns
Section titled “Returns”function — A function that cancels the callback if it has not run yet
Examples
Section titled “Examples”Defer non-urgent work
Section titled “Defer non-urgent work”Runs when the browser is idle, or after the timeout at the latest.
Cancel it
Section titled “Cancel it”The returned function cancels the callback if it has not run yet.
Related Types
Section titled “Related Types”WhenIdleOptions
Section titled “WhenIdleOptions”Options for whenIdle.
