Public BetaVitalSentinel is now live! Read the announcement
Performance

What is Main Thread?

The primary thread in a browser where JavaScript execution, DOM manipulation, and rendering operations occur.

The main thread is the browser's primary execution thread. It handles JavaScript, DOM updates, style calculations, layout, and painting. When blocked, the page becomes unresponsive.

Main thread responsibilities

  • Parsing HTML and CSS
  • Executing JavaScript
  • Handling user input events
  • Calculating styles and layout
  • Painting pixels to screen
  • Garbage collection

Main thread blocking

Long tasks (>50ms) on the main thread can cause:

  • Delayed response to clicks/taps
  • Janky scrolling
  • Poor INP scores
  • Visual stuttering

Keeping the main thread free

Break up long tasks

// Instead of one long task
function processAll(items) {
  items.forEach(process);
}

// Break into chunks
function processChunked(items) {
  requestIdleCallback(() => {
    // Process a chunk
  });
}

Use Web Workers

Move heavy computation off the main thread:

const worker = new Worker('heavy-task.js');
worker.postMessage(data);

Measuring main thread work

  • Lighthouse "Minimize main thread work"
  • Chrome DevTools Performance panel
  • Total Blocking Time (TBT)

Monitor your website performance

VitalSentinel tracks Core Web Vitals and performance metrics to help you stay ahead of issues.