Reduce JavaScript execution time

Lighthouse reports the time spent executing JavaScript files during page load in the Diagnostics section:

Lighthouse: Reduce JavaScript execution time
Fig. 1 — Reduce JavaScript execution time

How JavaScript execution slows down performance

JavaScript execution can slow down your performance in many ways:

  • Network cost. More bytes equals longer download times.
  • Parse and compile cost. JavaScript gets parsed and compiled on the main thread. When the main thread is busy, the page can't respond to user input.
  • Execution cost. JavaScript is also executed on the main thread. If your page runs a lot of code before it's really needed, that also delays your Time To Interactive, which is one of the key metrics related to how users perceive your page speed.
  • Memory cost. If your JavaScript holds on to a lot of references, it can potentially consume a lot of memory. Pages appear janky or slow when they consume a lot of memory. Memory leaks can cause your page to freeze up completely.

Ways to speed up improve JavaScript execution

More information

Last updated: Improve article