Identifying Long Tasks and Blocking Scripts
You'll learn how to spot tasks that hog the main thread for over 50ms and understand why they cripple your site's responsiveness.
What Are Long Tasks?
In the browser, everything happens on a single main thread—JavaScript execution, rendering, layout calculations, and user input handling. When a task monopolizes this thread for more than 50 milliseconds, it becomes a "long task." During this time, the browser can't respond to clicks, scrolls, or keyboard input, making your site feel frozen or janky.
Think of the main thread like a single-lane bridge. When a heavy truck (long task) blocks it for too long, all other traffic—including ambulances (user interactions)—gets stuck waiting.
Finding Long Tasks in DevTools
In the Performance panel recording you learned to capture earlier, long tasks appear as red triangles or red-flagged sections in the main thread timeline. These visual warnings immediately draw your eye to problematic areas.
When you click on a long task, DevTools reveals:
- Duration (anything over 50ms is problematic)
- The function call stack showing what code caused the blockage
- Source file and line number of the blocking script
Common culprits include heavy JavaScript parsing, complex DOM manipulations, synchronous network requests, or inefficient loops processing large datasets.
Why 50ms Matters
The 50ms threshold comes from user perception research. To maintain smooth 60fps animations and instant-feeling interactions, the browser needs to complete frames in under 16ms. A 50ms task blocks three full frames, creating noticeable lag users immediately feel.
Key Takeaway: Long tasks over 50ms freeze your UI and destroy responsiveness—use the Performance panel's red flags to identify blocking scripts and optimize or break them into smaller chunks.