How Long Tasks Block Interactivity
What you'll learn: How JavaScript tasks longer than 50ms freeze your interface and prevent users from interacting with your page.
The Problem with Long Tasks
When JavaScript runs on the main thread, the browser can't do anything else until that code finishes. This includes responding to user clicks, keypresses, scrolls, or any other interaction. A long task (anything taking more than 50ms) creates a noticeable freeze where the UI becomes unresponsive.
Think of it like a single-lane bridge: only one vehicle can cross at a time. When a slow-moving truck (your long-running JavaScript) is crossing, all the cars behind it (user interactions) must wait, no matter how urgent they are.
Why 50ms Matters
The browser constantly cycles through the event loop, checking for tasks to execute. If a JavaScript task takes 50ms or longer, users begin to perceive lag. Research shows that interactions should complete within 100ms to feel instant—but your JavaScript is only part of that budget. Rendering and painting also need time.
When you click a button during a long task:
- Your click gets queued in the task queue
- The current JavaScript continues running
- Your click waits... and waits
- Only when the long task completes does the browser process your input
- The delay between action and response feels broken
The Interactivity Penalty
Every millisecond beyond 50ms is time your users are locked out of their own experience. A 200ms task means 200ms where scrolling doesn't work, text fields won't accept input, and buttons ignore clicks. The page appears frozen, even though it's "working."
Key Takeaway: Long tasks (>50ms) monopolize the main thread and prevent the browser from processing user input, creating a frustrating, unresponsive experience that makes your application feel broken.