Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

A `requestIdleCallback` callback can wait 40 seconds because it asks the browser to run work during an idle period; it does not start a 40-second timer or promise prompt execution. Without a timeout, a busy page can keep postponing the callback for a potentially unbounded time. The 40-second wait is an illustrative scenario, not a universal limit or benchmark.

Why is `requestIdleCallback` taking so long?

The browser decides when the main thread is idle enough to run the callback. A page handling ongoing work may leave no suitable idle time, so the browser can postpone the callback. The W3C Working Draft for the API explicitly allows postponement for a potentially unbounded time under heavy load: W3C: Cooperative Scheduling of Background Tasks.

That makes the API useful for low-priority work, but unsuitable as the only mechanism for work that must finish by a deadline. A callback waiting 40 seconds is possible as a scenario; it does not indicate that the API has a 40-second limit or that every browser behaves that way.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What the callback’s deadline tells you

The callback receives an IdleDeadline object with two useful signals. They help you decide how much work to attempt, but do not make a large task safe to run in one go.

  • timeRemaining() estimates how much time remains in the current idle period. Use it to guide small chunks of work, then stop or reschedule if work remains.
  • didTimeout is true when the callback runs because its timeout expired rather than because the browser found an idle period.

See MDN’s IdleDeadline reference for the callback object’s behavior.

When should you use an idle callback?

Use `requestIdleCallback` when work can wait—and, where appropriate, be skipped—without breaking the user-facing task. Examples include cache pruning and precomputation. Ask four questions before scheduling work:

  • Must this work complete, or is it optional?
  • How long can it safely wait?
  • What would be the cost of running it while the page is busy?
  • What handles browsers without the API or situations such as the user leaving the page?

If the work must continue but should yield so the browser can handle input and painting, `scheduler.yield()` represents a different scheduling approach. The distinction is conceptual: use yielding for work that must continue while yielding control, and idle callbacks for work that can wait. Cross-browser support for `scheduler.yield()` is not established here, so check its availability for your target browsers before relying on it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What does a timeout change?

Passing a positive timeout asks the browser to queue the callback once that delay expires, even if doing so risks affecting performance. It is an escape from indefinite postponement, not a guarantee that the callback will run in a safe idle slot. Choose a timeout only after weighing the cost of running during a busy period against the cost of waiting longer. The W3C Working Draft describes this tradeoff at W3C: Cooperative Scheduling of Background Tasks.

How to handle required work and unsupported browsers

Keep a completion path for mandatory work

Do not make idle time the only route to completion. For example, an application might schedule ordinary draft-saving work during idle periods, while using a separate pagehide and sendBeacon path for page exit. This is an implementation pattern, not a guarantee that a particular save will always be delivered; design the application around its actual persistence and reliability needs.

Feature-detect the API

MDN classifies `requestIdleCallback` as limited availability and not Baseline. Check for it before calling it, as shown in this pattern:

if ('requestIdleCallback' in window) {
  window.requestIdleCallback(runSmallChunk, { timeout: 1000 });
} else {
  window.setTimeout(runSmallChunk, 0);
}

The timer fallback above can provide a route to run the callback-shaped work, but it cannot tell whether the main thread is idle. Treat it as a timer-based fallback, not as equivalent idle scheduling. If the task is required, make sure the fallback and other completion paths satisfy that requirement. MDN’s requestIdleCallback reference covers availability and usage.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Where does the 40-second figure come from?

The figure is the article’s illustrative scenario, not a published general measurement. The underlying behavior is the important point: without a timeout, the API offers no guaranteed maximum wait. The browser schedules low-priority work when it considers the main thread idle, and heavy activity can delay that opportunity.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.