Skip to content
Performance & Accessibility

Long Tasks and the Main Thread, Done Properly

The browser's main thread handles layout, painting and most JavaScript, and any single task that runs for more than 50 milliseconds blocks it from responding to input.

MediaScaleUp Editorial Team 2 min read 15 views
Long Tasks and the Main Thread, Done Properly

Where most projects go wrong

The usual mistakes:

  • Large synchronous loops on page load
  • Heavy work inside input event handlers
  • Loading every script at once
  • Assuming fast devices represent users

What good looks like instead

  • Profile interactions in DevTools Performance panel
  • Split large tasks and yield between them
  • Defer non-urgent work until after interactions
  • Move heavy computation off the main thread
  • Measure improvements with INP field data
What to do and what to avoid with long tasks and the main thread, side by side
Good practice against the usual mistakes, from the sources listed below.

Why it matters

Long tasks are the main cause of pages that look loaded but do not respond to clicks and taps, which shows up in Interaction to Next Paint.

The specs that matter

Published figures for Long Tasks and the Main Thread
MeasureFigure
Long task threshold50 milliseconds
Why 50 mskeeps responses within about 100 milliseconds of input
Yieldingbreaking work up lets the browser handle input between chunks
scheduler.yield()an API for yielding to the main thread in supporting browsers

Knowing when to hand it over

Tip: Bring in help when interactions feel delayed, when INP is poor, or when a framework application blocks the main thread.

Where this comes from

The figures and practices above come from the sources listed.

Working on something like this?

We take on Performance & Accessibility work for teams who want it done once, properly. Tell us what you are building and we will tell you honestly whether we are the right studio for it. Start a project.

Where to go next

Spotted something wrong? Report an error on this page. We correct on the page and say what changed.

All services

The work behind this article, and what it costs.

MediaScaleUp Editorial Team

Articles here are researched, written and checked by the MediaScaleUp studio team before they are published, and dated when they are reviewed.

Keep reading

More in Performance & Accessibility