window.requestIdleCallback()

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: Esta é uma tecnologia experimental
Verifique a tabela de compatibilidade entre Navegadores cuidadosamente antes de usar essa funcionalidade em produção.

O método window.requestIdleCallback() enfileira uma função para ser executado durante períodos onde o navegador está ocioso. Isso permite que desenvolvedores realizem tarefas de baixa prioridade em relação a o event loop em segundo plano. As funções são geralmente chamadas na ordem first-in-first-out (primeiro-a-entrar-primeiro-a-sair); Contudo, callbacks nos quais tem um timeout especificado, podem ser chamados na ordem out-of-order (fora-de-ordem) se necessário, afim de executar antes do tempo limite.

Você pode chamar requestIdleCallback() com uma função callback ociosa para agendar outro callback para ter lugar não antes da próxima passagem pelo event loop.

Nota: Um timeout é altamento recomendado, caso contrário, é possível que vários segundos passem antes que a função callback seja chamada.

Syntax

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

Return value

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

Parameters

callback

A reference to a function that should be called in the near future, when the event loop is idle. The callback function is passed an IdleDeadline object describing the amount of time available and whether or not the callback has been run because the timeout period expired.

options Optional

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

  • 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 callback will be called during the next idle period, even if doing so risks causing a negative performance impact.

Example

Especificações

Specification
requestIdleCallback()
# the-requestidlecallback-method

Compatibilidade com navegadores

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
requestIdleCallback

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

See also