Home / Fix guides / Reduce unused JavaScript / WordPress

WordPress fix guide

How to reduce unused JavaScript on WordPress

The warning means your pages download JavaScript that is not needed to show the page. On WordPress it almost always comes from plugins, your theme or a page builder loading scripts on every page.

PageSpeed Insights and Lighthouse show "Reduce unused JavaScript" when a page downloads script code that is not used while the page loads. The audit lists each file with its size and an estimate of how many bytes are wasted. WordPress does not cause this by itself. It happens because every plugin, your theme and any page builder can add its own scripts, and many add them to every page whether the page needs them or not.

You will rarely get the number to zero, and you do not need to. The goal is to remove what is clearly pointless and delay what is not needed straight away. The general explanation is in the unused JavaScript guide. This page covers the WordPress specifics.

Step by step

  1. Back up and, if you can, use a staging copy. Most hosts offer a staging site in their control panel. Changing script loading can break menus, forms or sliders, so test there first. If you have no staging, take a full backup and make changes one at a time.
  1. Run PageSpeed Insights on your key pages. Test the home page and one or two important pages (a service page, a product page). Open the "Reduce unused JavaScript" item and note which files are listed. Paths like /wp-content/plugins/plugin-name/ or /wp-content/themes/theme-name/ tell you who owns the file. Files from other domains are third party scripts (see the section further down).
  1. Find the heaviest sources. In Chrome, open DevTools, press Ctrl+Shift+P (Cmd+Shift+P on Mac), type "Coverage", choose "Show Coverage", then reload the page. It shows how much of each file ran. The free plugin Query Monitor also lists scripts loaded on a page, and which plugin or theme added each one, under its Scripts section.
  1. Remove plugins you do not need. Deactivate and delete plugins you no longer use. A deactivated plugin does not load scripts, but a forgotten active one does. Look for old sliders, social share buttons, popup tools and duplicate form plugins.
  1. Stop plugins loading scripts on pages that do not use them. A contact form plugin only needs its script on the contact page. Some plugins have a setting for this, usually in their own settings screen under something like "Advanced" or "Performance". If not, a plugin such as Asset CleanUp or Perfmatters lets you switch off a script on chosen pages. Both have a per page view of loaded scripts, and Perfmatters is paid. Turn off one script, check the page, and move on.
  1. Delay scripts that are not needed at first. Chat widgets, tracking and animation scripts can wait until the visitor scrolls or clicks. WP Rocket (paid) has "Delay JavaScript execution" under its File Optimization tab. Perfmatters and FlyingPress have similar options. Start with the default settings and add exclusions if something breaks.
  1. Use defer for scripts that must load. The "Defer" setting lets the page draw before the script runs. Many optimization plugins offer it, including Autoptimize and WP Rocket. Be careful with jQuery: if other scripts depend on it, deferring it alone can cause errors.
  1. Check your theme and page builder settings. Elementor, Divi and similar builders often have performance options, such as loading only the features used on a page or turning off unused widgets. Look under the builder's own settings or experiments section. Names vary by version. Also check whether your theme loads large libraries (sliders, icon sets, animation code) that you never use.
  1. Retest and click through the site. Run PageSpeed Insights again. Then test the menu on mobile, forms, search, checkout and any popups. A better score is no use if the contact form stopped working.

Common WordPress sources

  • Page builders and large themes: they bundle code for every feature, even unused ones.
  • Sliders and galleries: often loaded sitewide for one section on one page.
  • WooCommerce: its scripts (such as cart fragments) can load on pages that are not shop pages. Asset CleanUp or Perfmatters can restrict them, but test the cart and checkout carefully.
  • Contact and popup plugins: frequently load on every page.
  • Emoji and jQuery Migrate: older WordPress setups sometimes load these. Disable them only if your optimization plugin offers it and you have tested.

Third party scripts

If the audit lists files from Google Tag Manager, Facebook, a chat service or ad networks, you cannot shrink those files. You can only load fewer of them, or later. See third party scripts slowing a WordPress site. Merging and minifying files is a separate topic, covered in unminified CSS and JavaScript.

When to ask a developer

If the unused code comes from your theme itself, or from a page builder with no relevant options, the real fix is a lighter theme or custom code that loads scripts only where needed. That is a developer job. Developers use wp_enqueue_script and wp_dequeue_script in a child theme or small plugin, so changes survive updates.

Keeping track

This problem returns whenever you add a plugin. SiteMonday checks speed and Core Web Vitals in week 4 and ranks what to fix, but making the changes is up to you or your developer.

Not on WordPress? Read the general guide to reduce unused javascript, or the guide for Shopify, Wix, React, Next.js, Google Tag Manager, Elementor.

Questions

Will removing unused JavaScript break my WordPress site?

It can, if you switch off a script that something still needs. Change one thing at a time, ideally on a staging site, and test menus, forms and checkout after each change.

Do I need a plugin to fix this?

Not always. Deleting unused plugins and adjusting theme or builder settings costs nothing. Plugins like Asset CleanUp, Perfmatters or WP Rocket help when you need to control scripts page by page or delay them.

Why does the warning stay after I install a caching plugin?

Caching speeds up delivery of files but does not change how much script is loaded. You need to remove, restrict, defer or delay scripts to reduce the unused code.

Can I get to 0 KB of unused JavaScript?

Rarely, and you do not need to. Focus on large files that load on pages where they are not needed, especially at the top of the list.

Is it safe to delay or defer jQuery in WordPress?

It is risky, because many themes and plugins expect jQuery to be ready. If you try it, test thoroughly and use your optimization plugin's exclusion list for anything that breaks.

More WordPress fixes