Home / Hardware and Performance / Scheduler API Demo

Scheduler API Demo in JavaScript, Free with Live Demo

Free Scheduler API demo in plain JavaScript. Run the same heavy job blocking, chunked with setTimeout and with scheduler.yield(), and watch the jank.

Open live demoDownload HTML fileView code on GitHub
Scheduler API Demo JavaScript project: see why long tasks freeze a page and how to fix it

Runs on: Scheduler API. scheduler.postTask: Chrome, Edge and Firefox 142+. scheduler.yield: Chrome and Edge 129+. Others use a setTimeout fallback.

What is the Scheduler API Demo?

A moving ball and a text box show how smooth the page feels. Run the same heavy job three ways and watch which one freezes the page, which one keeps it moving, and how long each takes.

scheduler.yield() lets a long loop pause so the browser can handle clicks and paint, then continue ahead of other waiting work. scheduler.postTask() runs tasks by priority, and a second demo shows the order.

Good for

  • Fixing poor INP scores
  • Apps with heavy data work
  • Learning how the main thread works
  • Performance talks and workshops

What this project does

How it works

  1. Break the workThe heavy job is a loop. Every few milliseconds it stops to let the browser handle input and paint.
  2. Yield smartlyawait scheduler.yield() pauses and then continues ahead of other queued tasks, so the job still finishes quickly.
  3. PrioritizepostTask runs callbacks by priority, so user-blocking work jumps ahead of background work.

The key JavaScript

This is the heart of the project. The full file has the rest, including the screen layout and error handling.

async function processAll(items) {
  let last = performance.now();
  for (const item of items) {
    doWork(item);
    if (performance.now() - last > 10) {         // every 10 ms...
      await scheduler.yield();                   // ...let input and paint happen
      last = performance.now();
    }
  }
}
scheduler.postTask(() => saveDraft(), { priority: "background" });
scheduler.postTask(() => showMenu(), { priority: "user-blocking" });  // runs first

How to use it

  1. Click Download HTML file above.
  2. Open the file in a code editor, like VS Code.
  3. Run it from a local server with npx serve . so the camera, microphone and AI features are allowed.
  4. Change the text and colors, then upload it to GitHub Pages, Netlify or your own site. It is one file with no build step.

Questions people ask

What is scheduler.yield()?

A function that pauses your code and lets the browser do other work, then resumes your task first. It is the easiest way to break up long tasks.

How is it different from setTimeout?

After setTimeout your code waits at the back of the queue. After scheduler.yield() it continues sooner, so the job finishes faster.

Which browsers support it?

scheduler.postTask is in Chrome, Edge and recent Firefox. scheduler.yield is in Chrome and Edge 129 and newer. The demo falls back to setTimeout.

More Hardware and Performance projects