The short fix
- Test the page and note the scripts with the most unused code.
- Match each script to a plugin, the theme or an outside service by its address.
- Remove plugins and tracking tags nobody uses.
- Unload the rest on pages that don’t need them: sliders, forms, maps, product-page extras.
- Delay non-essential scripts until the first interaction, then test the cart and checkout.
What PageSpeed Insights is telling you
Reduce unused JavaScript appears under Diagnostics in PageSpeed Insights. Lighthouse lists every script with more than 20 KiB of code that didn’t run during the page load, with its size and the estimated saving. Scripts from outside services such as tag managers, pixels and chat widgets are listed too.
In a FlashMax report the same problem is the card JavaScript the page never uses. It shows up when a page carries 150 KB or more of unused JavaScript.
“Unused” means it didn’t run during this load. Lighthouse doesn’t open the menu, zoom a product photo or add anything to the cart, so code for those actions counts as unused. The goal is less waste, not zero.
Why it slows the page
Unused JavaScript costs twice. First it’s downloaded, competing for bandwidth with the main image, which can delay Largest Contentful Paint (LCP, 25% of the Lighthouse score). Then the phone has to deal with it: web.dev notes that even unused JavaScript must be downloaded, parsed, compiled and then executed, which keeps the main thread busy.
A busy main thread shows up in the lab as Total Blocking Time (TBT, 30% of the score) and, for real visitors, as slow responses to taps, which Google measures as INP. Lighthouse can’t measure INP itself; TBT is its stand-in.
How common it is
In our study of 40,951 WooCommerce stores, 76.6% (31,357 stores) carried 150 KB or more of unused JavaScript on the home page. Their median phone score was 48, against 66 for stores without it, one of the widest gaps in the study. It’s still a correlation, not proof: stores with one problem usually have others too. The median store loaded about 646 KB of JavaScript in the phone test. Details: WooCommerce speed study.
How to find the scripts
- FlashMax: paste your address into the free speed test; the card JavaScript the page never uses lists the scripts behind it.
- PageSpeed Insights: open Diagnostics → Reduce unused JavaScript on the Mobile tab and start with the largest savings.
- Chrome DevTools Coverage: open the Command Menu, type
coverage, choose Show Coverage and click Reload. Gray is unused bytes, green is used. Recording continues while you interact, so open the menu and add a product to the cart to see how much of a script those actions need.
Then read the addresses. /wp-content/plugins/plugin-name/ belongs to a plugin and /wp-content/themes/theme-name/ to the theme. Other domains, such as googletagmanager.com or connect.facebook.net, are services you or an agency added; our guide to third-party code covers those.
How to fix it on WordPress and WooCommerce
Chrome’s advice for WordPress is to reduce, or switch, the plugins that load unused JavaScript. Work in this order: removing beats unloading, and unloading beats delaying.
1. Remove what nobody uses
Deactivate and delete plugins you no longer need, remove old tags from Google Tag Manager or the theme header, and switch off theme modules you don’t use. Web.dev puts it simply: if you aren’t using a library, remove it.
2. Load scripts only where they’re needed
A slider, a form, a map, a size-chart popup or a gallery zoom rarely needs to load on every page. Asset CleanUp unloads CSS and JavaScript from its CSS & JS Manager, per page or site-wide with load exceptions. Turn on its Test Mode first, so only you see the change while you check the page.
WooCommerce already does part of this. Since version 7.8 it no longer loads the cart fragments script (wc-cart-fragments) on every page by default. It still loads where the Cart widget is active, or where a theme or plugin lists it as a dependency or adds it in code. For a live mini cart, WooCommerce recommends the Mini-Cart block, which doesn’t use cart fragments.
Developers can load their own scripts conditionally. This enqueues a script on product pages only:
add_action( 'wp_enqueue_scripts', function () {
// Load the size-chart script on product pages only.
if ( function_exists( 'is_product' ) && is_product() ) {
wp_enqueue_script( 'my-size-chart', get_stylesheet_directory_uri() . '/js/size-chart.js', array(), '1.0', true );
}
} );3. Delay what can wait
Some scripts belong on the page but not in the first seconds: chat widgets, review carousels lower down, some tracking. Delaying them until the visitor scrolls, taps or moves the mouse takes them out of the page load.
- WP Rocket: File Optimization tab → Delay JavaScript execution. Tick plugins that conflict under One-click exclusions, and add other scripts to Excluded JavaScript Files.
Delaying doesn’t delete the code. It runs on the first interaction instead, so a very heavy delayed bundle can make that first tap feel slow. Remove and unload first, delay second.
Shopify and hand-built sites
Shopify: most extra JavaScript comes from apps and tags. Shopify notes that uninstalling an app doesn’t automatically remove its code from your theme, so ask the developer how to remove it completely. Shopify also advises auditing your tag manager and removing unused or low-value tags. In theme code, load a script only on the template that uses it:
{% if template.name == 'product' %}
<script src="{{ 'product-form.js' | asset_url }}" defer></script>
{% endif %}Hand-built sites: split bundles so each page loads only its own code, load features such as a gallery zoom when they’re first used, and drop libraries you barely use. Shopify’s theme docs make a point that applies everywhere: every script, even a deferred one, costs bandwidth and main-thread time, so removing a script beats deferring it.
Mistakes to avoid
- Unloading scripts on cart or checkout. Payment, shipping and coupon code can look unused at load. Leave the cart, checkout and account pages alone unless you test a real order.
- Delaying scripts that build the page. A slider, menu or product gallery that draws visible content can show blank or jump when delayed. Exclude it.
- Combining JavaScript on top of delay. WP Rocket says JavaScript combining from other plugins or the theme should be off, or display problems may follow.
- Forgetting the consent banner and analytics. Check that the cookie banner still appears and that your analytics and ad conversions still record after you delay scripts.
- Hiding scripts from the test only. Rules that skip scripts just for Lighthouse fake the score and do nothing for visitors or for field data.
How to check the fix worked
- Clear the plugin, server and CDN caches.
- Re-test two or three times and compare the unused JavaScript total, TBT and LCP; lab results vary between runs.
- On a phone, logged out, test the menu, search, product options, add to cart, the mini cart and a full checkout.
- Watch real tap responsiveness in field data: the Core Web Vitals report in Search Console and CrUX cover the previous 28 days, so allow about four weeks.
Questions people ask
Why does PageSpeed say my JavaScript is unused when the site needs it?
Lighthouse loads the page once and doesn’t click anything. Code for menus, the cart, product options and checkout counts as unused in that test even though visitors need it. Focus on scripts that do nothing on that page at all.
Is it safe to delay all JavaScript?
Not without testing. Delay suits chat, social embeds and many tracking tags, but scripts that draw visible parts of the page or run checkout should load normally. Use the plugin’s exclusions and place a test order before you call it done.
Does WooCommerce load cart fragments on every page?
Not since WooCommerce 7.8. It loads wc-cart-fragments only where the Cart widget is active, where another script depends on it, or where code enqueues it. If you see it on every page, your theme or a plugin is asking for it.
What is the difference between unused JavaScript and main-thread work?
Unused JavaScript is about code downloaded but not run. Main-thread work is the time the phone spends running scripts. They often share a cause, too many scripts, so the same clean-up tends to help both.
Sources
- Reduce unused JavaScript (Lighthouse) — Chrome for Developers
- Remove unused code — web.dev
- Coverage: Find unused JavaScript and CSS — Chrome DevTools
- Best practices for the use of the “cart fragments” API — WooCommerce Developer Blog
- Asset CleanUp — WordPress.org plugin page
- Delay JavaScript execution — WP Rocket docs
- Use defer and async on non-critical scripts — Shopify.dev
- Improving your online store performance — Shopify Help Center
Rather have it done?
The FlashMax team fixes the issues in your report, on a copy first, and shows the before-and-after.
See the speed optimization service