JavaScript Execution Time

When JavaScript execution takes too long, it affects several functions vital to page performance:

  • Network cost: More memory equates to longer downloads
  • Parse and compile cost: JS is parsed and compiled on the main thread. When there is a hiccup on the main thread, the more time elapses before user input can be taken.
  • Execution cost: The more JS being executed in the main thread, the longer it takes to get to Time To Interactive (TTI).
  • Memory cost: If JS uses a large quantity of references, the more memory it could take up. Large amounts of memory download can slow pages and memory leaks potentially can freeze the page.

Tips for speeding up JavaScript execution

  • Use code splitting to only parse code your users actually need.
  • Minify and compress code whenever possible.
  • Delete unused code.
  • Cache code with the PRPL pattern.