8 Tips To Reduce JavaScript Execution Time In WordPress

8 Tips To Reduce JavaScript Execution Time In WordPress

If you want to reduce JavaScript execution time in WordPress, you’ll need to find heavy JavaScript files in PageSpeed Insights (or Lighthouse) and optimize them.

You can reduce JavaScript execution time by removing unused JavaScript using an asset unloading plugin as well as minifying, combining, deferring, and delaying JavaScript files. Many of these optimizations can be done using caching plugins, Autoptimize, and Async JavaScript.

Long JavaScript execution times can also come from third-party code. Google Fonts, Google Analytics, and Tag Manager can all be hosted locally while other third-party JavaScript can be delayed using plugins like WP Rocket or Flying Scripts.

 

1. Find Problematic JavaScript Files

The first step to reducing JavaScript execution time is to open your PageSpeed Insights report and learn which files take a long time to execute.

  • Is it jQuery?
  • Is it from third-party code?
  • Is it from your page builder?

Your report should help narrow down where your heaviest JavaScript files are coming from.

You should also look at your third-party code report which we’ll get into in the 3rd tip.

 

2. Removed Unused JavaScript And CSS

Page builders, plugins, and other things might be loading JavaScript files across your entire WordPress site when they’re only being used in a few places. By removing unused JavaScript and CSS, you will essentially be trimming their files sizes which reduces their execution time.

This is typically done using asset unloading plugins like Asset CleanUp or Perfmatters (I wrote a comparison of the two, but I personally use Perfmatters).

Depending on which plugin you choose, enable test mode in Asset CleanUp or the script manager in Perfmatters.

Next, edit a page or post, view the JavaScript and CSS files loaded on the page, and disable all the files that are not being used. For example, if your social sharing plugin is loading on pages but it’s only being used on your blog, disable your social sharing plugin “everywhere but posts.”

Examples:

  • Disable slider plugins everywhere but pages that use sliders.
  • Disable contact form plugin everywhere but pages with forms.
  • Disable plugins that are only on the blog “everywhere but posts.”
  • Disable page builder features if you’re not using it (see image below).

Remove Elementor CSS JavaScript

 

3. Optimize Third-Party JavaScript

Third-party code can also cause long JavaScript execution times in WordPress.

Open your “third-party code” report in PageSpeed Insights and look at each third-party domain’s

[…]

 



This article was written by Tom Dupuis and originally published on Tom Dupuis.

Disclosure: Some of the links in this post are "affiliate links." This means if you click on the link and purchase the product, We may receive an affiliate commission.

Leave a Comment

You have to agree to the comment policy.

Show Your ❤️ Love! Like Us
Scroll to Top