Long Tasks API
ELI5 — The Vibe Check
The Long Tasks API is a snitch that tells you whenever JavaScript hogs the main thread for more than 50 milliseconds. It's like a hall monitor catching students running in the corridor — 'Excuse me, that script took 200ms. Detention!'
Real Talk
The Long Tasks API detects tasks that monopolize the UI thread for 50ms or more, helping identify sources of jank and poor interactivity. It uses PerformanceObserver to report long task entries with duration and attribution information.
Show Me The Code
new PerformanceObserver((list) => {
list.getEntries().forEach(entry => {
console.log('Long task:', entry.duration, 'ms');
});
}).observe({ type: 'longtask' });
When You'll Hear This
"The Long Tasks API showed a 300ms task from our date formatting library" / "Monitor long tasks in production to catch real-user jank"
Related Terms
Performance Budget
A performance budget is like a calorie limit for your website.
Time to Interactive
Time to Interactive is when your page stops being a beautiful painting you can't touch and actually starts responding to clicks.
Total Blocking Time
Total Blocking Time is the sum of all the moments your browser was too busy running JavaScript to notice you desperately clicking buttons.