Total Blocking Time (TBT)
Total Blocking Time (TBT) is a web performance metric that quantifies the total amount of time during which the main thread is blocked due to long tasks, preventing user input from being processed in a timely manner. A long task is defined as any task that takes more than 50 milliseconds to complete.
TBT is particularly important for evaluating a website or application's interactivity and responsiveness, as it provides insight into how quickly the user interface can respond to user input.
A lower TBT contributes to a more responsive and smooth user experience. To provide a good user experience, Google suggests sites should strive to have a TBT of less than 200 milliseconds when tested on average mobile hardware.
Improving Total Blocking Time can be achieved through various optimization techniques including:
- Minimize the impact of third-party scripts: Third-party scripts can contribute to TBT by executing long tasks on the main thread. Evaluate the necessity of third-party scripts, defer their loading, or use async attributes to minimize their impact on TBT.
- Prioritize input handling: Prioritize event handling related to user input, such as click or touch events, by utilizing microtask queues or wrapping input handlers in requestAnimationFrame().
- Use passive event listeners: Passive event listeners inform the browser that the event handler will not call preventDefault() to cancel the event. This allows the browser to optimize scroll and touch events, improving TBT.
- Optimize CSS: Heavy CSS can impact TBT due to the time required for style calculations and layout. Minimize the complexity of your CSS selectors, avoid using expensive CSS properties, and remove unused styles to optimize rendering performance.
- Debounce and throttle event handlers: Debouncing and throttling can help limit the frequency of event handlers being called, reducing the workload on the main thread and improving TBT. This is particularly important for events such as scrolling and resizing.
- Monitor and optimize main thread work: Regularly analyze main thread activity using browser performance tools, such as Chrome DevTools, to identify long tasks and areas for optimization.
These are just a couple of suggestions for optimizing your TBT results. Get into the performance-first mindset with our comprehensive frontend performance checklist.
Continuously monitor and analyze your website's performance to identify areas for improvement and maintain a high-performing site.