How To Remove Unused JavaScript In WordPress

How To Remove Unused JavaScript In WordPress

When testing your site in GTmetrix and Litehouse, you may come across an error to remove unused JavaScript.

In WordPress, you can remove unused JavaScript, CSS, and plugins using Asset CleanUp or Perfmatters. JavaScript can also be loaded by third-party code.

The first thing to do is check the source of where the JavaScript is being loaded (in GTmetrix Waterfall) so you can narrow down whether it’s from your site or a third-party source. For third-parties, try hosting files locally, delay loading them, or use browser hints like prefetch.

Most often however, most WordPress sites that need to remove JavaScript (including my own) use heavy page builders like Elementor or Divi. After trying everything in the book, I’m planning on moving from Elemetor to Oxygen Builder. Genesis Framework is also lightweight, but I recommend viewing your source code to see how many times your page builder shows up.


1. View Your JavaScript In GTmetrix Waterfall

Open your GTmetrix Waterfall chart and view the JavaScript tab. Look at each JavaScript file as well as it’s source and load time.

  • Is it jQuery?
  • Is it third-party services?
  • Is it your theme’s JavaScript files?

This should help you narrow down where your heaviest JavaScript files are. From my experience, most heavy JavaScript files come from page builders, third-party code (e.g. advertisements), and plugins. The next steps will help you reduce JavaScript in WordPress.

GTmetrix Waterfall JavaScript Files


2. Remove Unused JavaScript Files With Asset CleanUp

Asset CleanUp and Perfmatters both let you disable unused JavaScript.

If scripts or plugins are loading across your site but only need to load on certain pages, you can disable them everywhere else.

This is common with contact form plugins, social sharing, tables, slider, rich snippet, comment plugin, and JavaScript in page builders like Elementor. Asset CleanUp has a Test Mode which lets you test disabling JavaScript without breaking your website, while Perfmatters does not.

Step 1: Install Asset CleanUp Or Perfmatters

I prefer Perfmatters over Asset CleanUp because it lets you disable plugins everywhere except pages and posts, while Asset CleanUp only lets you disable plugins everywhere except pages. Perfmatters is also known for being more user-friendly.

Step 2: Enable Test Mode If Using Asset CleanUp

Asset CleanUp Test Mode




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.

Scroll to Top