Recommendations

Lighthouse
Metrics
Audits
PageSpeed (Legacy)
YSlow (Legacy)

Lighthouse: Avoid long main-thread tasks

Overview

Events like HTML/CSS parsing, JavaScript parsing/execution, among others, are "tasks" that run on the main-thread (by default).

When any one of these tasks run for longer than 50 ms (also known as a "long task"), they can delay, both First Paint, and the time it takes for your page to become fully interactive.

Ensure that you avoid long main-thread tasks, as much as possible, to deliver a good page experience to your visitors.

How does your site score on this audit?

How do long main-thread tasks affect page performance?

Every time your page loads, the browser uses the main-thread to handle most of the tasks related to rendering your page content, as well as, deal with user interaction.

Long-running JavaScript example
Long-running JavaScript (A,B,E in above) may block the main-thread for a long time, preventing the browser from executing other tasks, impacting your overall page load.

Long main-thread tasks prevent the browser from dealing with other processes that are essential in loading your page.

For example, a long-running JavaScript file will stop the browser from processing any other task until it has been parsed and executed.

Decreasing the number of long main-thread tasks improves your overall page performance by minimizing main-thread work.

What this means for your visitors is, they may see content faster on your page and can interact with it sooner.

Click here to learn more about minimizing main-thread work.

How does GTmetrix trigger this audit?

This audit is highly correlated with your Time to Interactive (TTI) metric.

Clicking this audit reveals which main-thread tasks ran for longer than 50 ms.

How to avoid long main-thread tasks

This audit lists all the long tasks that are running on the main-thread. Ensure that you incorporate good practices into your development workflow to minimize the main-thread work in the interest of web performance.

Read our minimize main-thread work documentation to learn more.

Note: This is an expert-level optimization

Only experienced developers are advised to improve this audit.

Summary

6.1.0
 *****