Home / Fix guides / Speed and Core Web Vitals

How to fix Reduce unused JavaScript

This warning means your page downloads JavaScript it does not use on that page, which slows it down. Fix it by removing scripts, plugins and apps you do not need and loading the rest only where they are used.

If PageSpeed Insights or Lighthouse shows a warning called Reduce unused JavaScript, it means your page downloads JavaScript code that it does not use while the visitor is looking at it. The browser still has to fetch, read and often run that code, so the page feels slower for no benefit. It is common, rarely an emergency, and usually fixable by removing things you no longer need.

What the warning means

JavaScript is the code that makes a page interactive: menus, sliders, chat widgets, tracking, cookie banners and forms. Many sites load all of it on every page, even when a page only needs a small part. A contact page may load the code for a photo gallery, a booking tool and a shop that only appear elsewhere.

The report lists files with how many kilobytes (KiB) could be saved. Most of the big entries come from one of three places:

  • Plugins, apps or page builder add-ons that load on every page
  • Third-party scripts such as analytics, ad pixels, chat, review widgets and embedded videos
  • Your own theme or app code, which contains more than the page needs

Why it matters

Heavy JavaScript delays the moment the page looks ready and the moment it responds to taps and clicks. Google uses speed and Core Web Vitals as part of how it assesses page experience, so a slow page can hold back your search results. Visitors on phones and older devices feel it most, and slow pages lose enquiries and sales. A page that freezes or lags also looks careless, which hurts trust. Unused code is also extra code that someone has to keep updated, which adds a small maintenance and security cost.

How to check your site for free

  1. Go to PageSpeed Insights (pagespeed.web.dev) and enter a page address. Test your home page and one or two important pages, not just one.
  2. Choose the Mobile tab, scroll to the Diagnostics or Opportunities area and open Reduce unused JavaScript.
  3. Note the file names and the estimated savings. The file path often shows the source: /wp-content/plugins/ points to a WordPress plugin, and an address belonging to another company points to a third-party script.
  4. For more detail, open the page in Chrome, press F12, open the Coverage tab (three dots menu, More tools, Coverage, or press Ctrl+Shift+P and type Coverage), then reload. It shows how much of each file actually ran.

Treat the numbers as estimates. They change between runs. Coverage only counts code that ran during that visit, so a script that only runs when someone clicks a menu can look unused when it is not.

How to fix it in general

Work from the biggest file down. These steps go from easiest to most technical.

  1. Remove what you do not use. Old plugins, apps, tracking pixels from finished campaigns, abandoned chat tools and duplicate analytics are the most common cause. Delete them, do not just switch them off.
  2. Load scripts only where needed. A form script needed on one page should not load on all of them. Many platforms and optimisation plugins let you limit a script to certain pages.
  3. Delay or defer non-essential scripts. Chat widgets, review badges and social embeds can wait until the visitor scrolls or interacts. The defer attribute on a script tag lets the page appear before the script runs.
  4. Replace heavy tools with lighter ones. A full slider library for one banner, or a large animation library for a small effect, can often be swapped for simple CSS or a smaller option.
  5. Split and trim your own code (developers). Code splitting loads each page's code only when needed, and tree shaking removes code that is never used. Common build tools such as webpack, Vite and Rollup support both.

Make one change at a time and test the page after each, because removing the wrong script can break a menu or a checkout.

Common platforms

WordPress. Most unused JavaScript comes from plugins and the theme. On a staging copy, deactivate plugins one by one and retest. The free Query Monitor plugin can show which plugin loads which script, and many caching or optimisation plugins have a setting to disable scripts on pages that do not need them. See the WordPress guide.

Elementor and other page builders. Builders can load code for widgets you never use. Look in the builder's settings for options about loading assets only when needed, and remove add-ons you do not use.

Shopify. Apps often add scripts to every page, and leftover code can stay in the theme after an app is uninstalled. Check theme.liquid and the app embeds in the theme editor, or ask a developer to. See the Shopify guide.

Wix and Squarespace. You cannot edit the platform's own code. Remove unused apps, extra animations and embedded widgets, and keep pages simple.

Google Tag Manager. A container can load many tags on every page. Review the tags, pause old ones, and set triggers so each tag fires only where it is needed.

React and Next.js. Use dynamic imports (import() or next/dynamic) for components not needed on first load, check bundle size with a bundle analyzer, and avoid importing a whole library when you need one function.

How to confirm it worked

Re-run PageSpeed Insights on the same pages, on Mobile, and compare the estimated savings and Total Blocking Time with your earlier results. Run it a few times, since single results vary. Then click through the site by hand: menu, forms, cart, checkout and cookie banner. If something broke, undo the last change. Related measures such as long JavaScript tasks often improve at the same time.

How to stop it coming back

  • Before adding a plugin, app or tag, ask who will use it and on which pages.
  • Every few months, review installed plugins, apps and tags and delete the ones nobody uses.
  • Test speed after each redesign or big change.
  • Ask your developer to keep an eye on code size whenever new versions of the site are released.

SiteMonday looks at speed and Core Web Vitals in week 4 and gives you a ranked fix list, but making the changes is up to you or your developer.

Step by step for your platform

Questions

Is unused JavaScript the same as broken JavaScript?

No. The code works, but your page downloads it without needing it on that page. The cost is slower loading, not errors.

Can I get the unused JavaScript warning down to zero?

Usually not, and you do not need to. Aim to remove the largest items and keep the page fast and working, rather than chasing a perfect score.

Will removing unused JavaScript break my site?

It can if you remove something the page really needs, such as a menu or checkout script. Change one thing at a time, test the page, and use a staging copy if you have one.

Why does the warning show scripts from other companies?

Analytics, ads, chat and embedded videos load code from their own servers, and that code counts too. You can remove those tools, delay them, or load them only on pages that need them.

Does this affect my Google rankings?

Speed and Core Web Vitals are part of how Google assesses page experience, and heavy JavaScript can slow both. It is one factor among many, so content and relevance still matter most.

Do I need a developer to fix it?

Often not. Removing unused plugins, apps and tags is something most site owners can do. Code splitting and bundle changes on custom sites are developer work.

Related problems