Reference guide · performance · Published 2026-08-16 · 3 min read

Using requestIdleCallback for non-critical background work

requestIdleCallback scheduling of background work, idle budget, timeout, and alternatives compared.

requestIdleCallback schedules a function to run in a browser's idle periods, when the main thread is not busy with a user interaction or a paint. It is a tool for deferring low-priority background work so it does not delay the things the user cares about.

See how it runs

Write an idle task

A typical pattern runs a chunk and re-schedules if the deadline runs out:

function processQueue(deadline) {
  while ((deadline.timeRemaining() > 0 || deadline.didTimeout) && items.length > 0) {
    const item = items.pop();
    // do the low-priority work for item
  }
  if (items.length > 0) {
    requestIdleCallback(processQueue, { timeout: 2000 });
  } else {
    done();
  }
}
requestIdleCallback(processQueue, { timeout: 2000 });

Choose alternatives

Need a website built, fixed, optimised, migrated or replaced?

This technical resource is written by CSMBAC, a small design and development studio. If you would rather hand the problem to a professional, the website service page explains how we build enquiry-ready websites.

Explore website services