Performance · JavaScript and CSS
Long JavaScript execution time
A script on this page spends about 350 milliseconds calculating as the page loads, which Lighthouse's slower test phone turns into over a second.
How this page is built
The page loads long-execution.js, which runs a calculation for about 350 milliseconds as the page loads. It works in 35 short chunks of 10 milliseconds, so it does not lock up the page, but the total is still more than Lighthouse allows once the processor is slowed down. The result is written below.
Result from the script: calculating
Why it matters
While the browser runs JavaScript it cannot do much else, so long execution delays the page becoming usable and makes taps and clicks slow to respond. Phones have much slower processors than laptops, so a script that feels fast on a developer’s machine can take several times longer for many visitors.
Lighthouse slows the processor down by four times to imitate a mid-range phone, then adds up the time each script spends parsing, compiling and running.
How to check it
Run Lighthouse or PageSpeed Insights on the page and look at the diagnostics. Crawl tools that run Lighthouse for each page, or that measure page resources, report the same finding across the site. Lighthouse lists each script with its total processing time. The Performance panel in Chrome’s developer tools shows the same work as a flame chart.
How to fix it
Remove code that is not needed, move heavy calculations off the main thread into a web worker, run work only when it is needed, and spread large tasks over time. Cache results instead of working them out again on every visit.