Reduce Unused JavaScript WordPress - Load Less, Delay the Rest (2026)
"Reduce unused JavaScript" is one of the most common PageSpeed Insights warnings on WordPress. It means your pages download JavaScript they don't use, usually from plugins, page builders and third-party services.
What the Warning Means
Lighthouse flags JavaScript files with more than 20 KiB of unused code on the page. Unused code still has to be downloaded, and much of it is parsed and compiled, which costs time on mobile.
On WordPress, unused JavaScript usually comes from:
- Plugins that load their scripts on every page, even where their feature isn't used.
- Page builders that load libraries for widgets not on the current page.
- Third-party tags like analytics, ads, chat and social embeds.
- Themes bundling features you've turned off.
Find the Unused JavaScript
Check PageSpeed Insights
The unused JavaScript diagnostic lists files and how much of each is unused.
Identify the source
URLs with /wp-content/plugins/name/ come from that plugin; external domains are third-party services.
Use the Coverage panel
In Chrome DevTools, the Coverage panel shows how much of each file runs on the page.
Check several page types
A file unused on the homepage might be essential on product pages.
Three Ways to Reduce It
| Approach | What It Does | Best For |
|---|---|---|
| Remove | Uninstall the plugin or service | Features you don't need |
| Unload per page | Stop a script loading on pages that don't use it | Plugins used on a few pages, like forms or sliders |
| Delay until interaction | Load the script only after the visitor interacts | Analytics, chat, pixels, social widgets |
| Defer | Run after HTML parsing | Scripts needed on load but not urgently |
Option 1: Remove What You Don't Need
The cleanest fix is deleting plugins and services you don't use. Review your plugin list and your tag manager for:
- Old tracking pixels for campaigns that have ended.
- Duplicate analytics tools.
- Social sharing or feed plugins nobody uses.
- Sliders, galleries or popups you've replaced.
Option 2: Unload Scripts Where They're Unused
Many plugins load their JavaScript sitewide. A contact form plugin's script on every page is a classic example.
- Check plugin settings: some let you load assets only on pages with their shortcode or block.
- Use your page builder's options: builders often have performance settings to load widget scripts only when used.
- Use a script manager: plugins like Perfmatters and Asset CleanUp let you disable specific scripts on specific pages or post types.
Test carefully after unloading, since some scripts are needed in places you don't expect, like a form in a footer widget.
Option 3: Delay JavaScript Until Interaction
Delaying doesn't reduce what's downloaded eventually, but it removes the scripts from the initial load, which is what PageSpeed Insights and real visitors care about first. Unused JavaScript warnings often shrink or disappear because the scripts no longer load during the test.
WP Rocket's Delay JavaScript execution handles this across the site with one-click exclusions for scripts that must run early. WP Rocket's documentation notes it can't remove unused code from files, but delaying is how it reduces the impact. See Delay JavaScript exclusions.
Common Sources by Plugin Type
| Source | Common Fix |
|---|---|
| Contact form plugins | Load only on pages with forms |
| Sliders and galleries | Load only where used, or replace with static images |
| Page builder widget libraries | Enable the builder's per-widget asset loading |
| WooCommerce scripts on non-shop pages | Unload cart scripts on blog and info pages where safe |
| Social sharing and feeds | Replace with simple links; delay embeds |
| Analytics and tag managers | Consolidate tags; delay non-essential ones |
| Chat widgets | Delay until interaction |
| jQuery and plugins depending on it | Choose plugins that don't need jQuery where possible |
Using the Coverage Panel Step by Step
Open Chrome DevTools
Visit the page logged out and open developer tools.
Open Coverage
Use the command menu to show the Coverage panel.
Start recording and reload
Coverage records which code runs during the load.
Sort by unused bytes
The biggest files with the most unused code rise to the top.
Interact with the page
Click menus and buttons; the unused percentage drops for code those interactions need.
Note the sources
File paths tell you which plugin, theme or service each file belongs to.
Remember that some code is unused during load but needed later, for example a lightbox that runs only when someone clicks an image. That code is a good candidate for delaying rather than removing.
Unloading vs Delaying: Which to Choose
| Situation | Better Choice |
|---|---|
| Script isn't needed on this page at all | Unload it on this page |
| Script is needed, but only after interaction | Delay it |
| Script must run immediately for the first screen to work | Keep it, defer if possible |
| Third-party tracking that should fire on every visit | Keep, or delay and accept some data loss |
| You're not sure what a script does | Delay first and test, rather than unloading |
Combining both works well: unload scripts from pages that never need them, then delay what's left.
Mistakes to Avoid
- Unloading jQuery when other scripts depend on it, which breaks features site-wide.
- Delaying scripts the first screen needs, like a sticky header or above-the-fold slider, so they appear broken until interaction.
- Testing only the homepage, missing breakage on product pages, forms or checkout.
- Stacking several optimization plugins that all modify scripts, which makes conflicts hard to trace.
Unused JavaScript and Core Web Vitals
Unused JavaScript affects TBT and INP most, because downloaded scripts are parsed and often executed on the main thread. It can also delay LCP when scripts compete for bandwidth with the main image.
See reducing Total Blocking Time and improving INP.
A Worked Example
A blog's PageSpeed report lists unused JavaScript from a slider plugin, a form plugin, a social sharing plugin and two analytics tags. The slider only runs on the homepage, and the form only on the contact page.
The owner configures the form plugin to load only where its block appears, replaces the homepage slider with a static hero image and removes the slider plugin, switches social sharing to simple links and delays both analytics tags until interaction. The unused JavaScript warning disappears from most pages, and TBT drops substantially.
Reduce Unused JavaScript WordPress FAQ
What does "reduce unused JavaScript" mean?
Your page downloads JavaScript files where much of the code isn't used. Lighthouse flags files with more than 20 KiB of unused code.
Can WP Rocket remove unused JavaScript?
It can't remove code from inside files, but Delay JavaScript execution keeps those scripts out of the initial load, which reduces their impact.
Is it safe to unload plugin scripts?
Yes, on pages where the plugin isn't used, but test carefully, because some features appear in places you might not expect.
Does unused JavaScript affect SEO?
Indirectly, through Core Web Vitals like INP and LCP, which Google uses in its ranking systems.