UX Robot guide

Reduce unused JavaScript: what it means and how to fix it

Reduce unused JavaScript explained: what the Lighthouse warning measures, how to find the files, and the fixes, with real numbers from Target and Wayfair.

By the UX Robot teamUpdated 15 minute read

If PageSpeed Insights or Lighthouse tells you to “Reduce unused JavaScript”, your page downloads scripts that it does not run while it loads. Phones fetch those bytes, unpack them and often execute parts of them before the visitor can do anything, so the page appears later and answers taps more slowly. This guide explains what the warning measures, how to find which files cause it, and how to reduce unused JavaScript without breaking your website. The examples are real: UX Robot page audits of Target’s and Wayfair’s home pages on a phone in November 2026.

In short

  • Lighthouse lists any script with more than 20 KiB it did not use while the page loaded, and estimates the download you would save.
  • The warning itself does not change your performance score. The time those scripts cost shows up in the measures that do, mainly Largest Contentful Paint and Total Blocking Time.
  • Most unused JavaScript comes from two places: one big bundle that holds code for every page, and other companies’ tags such as ads, analytics and session recording.
  • The fixes are to split bundles by page and feature, load code when the visitor needs it, remove tags nobody uses and delay the rest until after the page has appeared.
  • On Target’s home page Lighthouse estimated 1,235 KiB of unused JavaScript; on Wayfair’s, 473 KiB.

What “Reduce unused JavaScript” means

It means Lighthouse watched your page load and found script files where a large part of the code never ran. It lists each file with its size and the bytes it did not use, and adds up an estimated saving. Unused here means unused during page load, not useless.

While the page loads, Lighthouse records which parts of every JavaScript file the browser actually executes. Google’s documentation for the audit says Lighthouse “flags every JavaScript file with more than 20 kibibytes of unused code”. A kibibyte (KiB) is 1,024 bytes, so 20 KiB is roughly 20 kilobytes. Smaller leftovers are ignored, which is why a page can pass the audit and still carry some dead weight.

The report shows each file’s address, its transfer size and the potential savings, then a total such as “Est savings of 473 KiB”. PageSpeed Insights shows the same audit, because it runs Lighthouse on Google’s servers.

Two things are worth knowing before you start deleting code. First, code that did not run during load may still be needed later, when someone opens the menu, filters products or adds something to the cart. The aim is to stop sending it up front, not to remove features. Second, the number is an estimate from one load of one page. Run it on a few templates, such as home, category, product and checkout, before you decide what to change.

Why unused JavaScript slows the page for visitors

Every script has to be downloaded, and most are also parsed and compiled before they run. On a phone that work competes with drawing the page and answering taps. Less JavaScript means the main content appears sooner and the page responds when people first touch it.

Images can arrive and appear in any order, but JavaScript sits on the browser’s main thread, the same thread that lays out the page and reacts to taps and typing. While it is busy with scripts, a tap on a menu button waits. Lighthouse measures that waiting as Total Blocking Time, and real visitors feel it as Interaction to Next Paint, which Google says should be “200 milliseconds or less” for a good experience in its guide to optimizing INP.

Unused code also costs data. A shopper on a capped plan pays for every kilobyte, and on a weak connection each extra file delays the ones that matter. Google’s scoring page is clear that “only metrics contribute to your Lighthouse Performance score, not the results of Opportunities or Diagnostics”, but it adds that fixing them will likely improve the metric values. In Lighthouse 10 and later, Total Blocking Time counts for 30% of the score and Largest Contentful Paint for 25%, and scripts weigh on both.

558 KB JavaScript on the median mobile page (Web Almanac 2024, June 2024 crawl).
206 KB Unused during page load on the median mobile page, 44% of the JavaScript it receives.
22 JavaScript requests on the median mobile page; 68 at the 90th percentile.
30% Weight of Total Blocking Time in the Lighthouse performance score (Chrome for Developers).

The problem is common. The JavaScript chapter of the HTTP Archive Web Almanac 2024, based on pages crawled in June 2024, found the median JavaScript payload “reaching 558 kilobytes on mobile”, with roughly half of the bytes downloaded going unused during page load: 206 kilobytes, or 44%, at the median on mobile. At the 90th percentile the unused share reached 818 kilobytes. The same chapter shows the median mobile page receiving more of its JavaScript from other companies’ hosts (375 KB) than from its own (168 KB), which matters for where you look first.

Two real examples: Target and Wayfair

Lighthouse estimated 1,235 KiB of unused JavaScript on Target’s home page and 473 KiB on Wayfair’s, in UX Robot page audits on a phone on November 26, 2026. Both pages mix their own framework bundles with other companies’ tags, and both spend seconds running scripts before they settle.

We ran UX Robot page audits of Target’s home page and Wayfair’s home page on a 390 by 844 pixel phone screen, signed out, during their Black Friday sales. Each audit measures the page with Lighthouse on UX Robot’s server and checks it in a real browser. Both pages do a lot well: clear deal sections, real-text prices and product names, alt text on every visible image and menus that opened in about a tenth of a second when we tapped them. The figures below are one lab test of one page each on a busy sales day; the pages may have changed since.

Target: 1,235 KiB unusedMeasured
Target's home page on a phone on November 26, 2026, with the search bar, a Sign in for the best experience panel open on arrival and the Black Friday 4-day deals hero below it
Target’s home page as the audit saw it. Lighthouse estimated 1.66 seconds of load time in its unused scripts.
Wayfair: 473 KiB unusedMeasured
Wayfair's home page on a phone on November 26, 2026, with the search box, an orange Black Friday strip and a Sealy mattress offer of up to 60% off in the hero
Wayfair’s home page as the audit saw it. Lighthouse estimated 0.45 seconds in its unused scripts.

Target. The audit scored the page 35 for performance on a phone, with the main content appearing after 10.1 seconds in the lab and 3,962 milliseconds of Total Blocking Time. Lighthouse spent 11.5 seconds running JavaScript and estimated 1,235 KiB of unused JavaScript, worth 1.66 seconds of load time. UX Robot rated the unused JavaScript high severity because of that saving. The five largest files tell a typical story: the site’s own Next.js app bundle and shared vendor bundle, Google’s ad library, a script served from target.com itself, and FullStory’s session recording script.

Target home page: unused JavaScript in the five largest files, KiB
  • _app bundle (assets.targetimg1.com)243 KiB
  • pubads_impl.js (Google ads)118 KiB
  • vendor bundle (assets.targetimg1.com)93 KiB
  • script on www.target.com71 KiB
  • fs.js (FullStory)70 KiB
The five files Lighthouse listed first account for 595 of the 1,235 KiB. Measured in a UX Robot page audit on November 26, 2026.

Wayfair. Wayfair scored 36, with the main content at 11.2 seconds in the lab and 2,888 milliseconds of Total Blocking Time. Lighthouse spent 8.3 seconds running JavaScript and estimated 473 KiB of unused JavaScript, worth 0.45 seconds, which UX Robot rated medium. Here the largest unused file is a script on Wayfair’s own prx.wayfair.com subdomain, followed by Quantum Metric’s analytics script and three chunks of the site’s own Next.js build. Wayfair’s bundles are already split into many small chunks, which is why its own files are smaller than Target’s single app bundle.

Wayfair home page: unused JavaScript in the five largest files, KiB
  • main.min.js (prx.wayfair.com)109 KiB
  • quantum-wayfair.js (Quantum Metric)68 KiB
  • chunk 40427 (assets.wfcdn.com)55 KiB
  • chunk 3209 (assets.wfcdn.com)46 KiB
  • chunk 24666 (assets.wfcdn.com)38 KiB
The five files Lighthouse listed first account for 316 of the 473 KiB. Bars use the same scale as Target’s chart. Measured in a UX Robot page audit on November 26, 2026.

Neither result means these teams did something careless. Large retailers run ads, analytics, testing and bot protection on their home pages for good reasons, and each tag arrives with code for features the home page never uses. The lesson is in the split: some of the waste is the site’s own code, which developers can change today, and some belongs to other companies, which only a decision about whether and when to load that tag can change.

How to find which scripts are unused

Start with the files Lighthouse lists, then open Chrome DevTools’ Coverage panel to see exactly which lines ran. Sort by unused bytes, note who owns each file, and decide whether it should load later, load on fewer pages or not load at all.

  1. Read the Lighthouse listIn PageSpeed Insights or the Lighthouse panel in DevTools, open Reduce unused JavaScript and copy the file addresses with their sizes and savings.
  2. Open the Coverage panelIn Chrome DevTools, open the Command Menu, type “coverage” and choose Show Coverage. It opens in the drawer at the bottom.
  3. Record a page loadClick the reload button in the panel. Chrome reloads the page and lists each file with its total bytes and unused bytes. In Google’s words, “The gray section of the bar is unused bytes. The green section is used bytes.”
  4. Open a file to see the linesClick a row to open the file in the Sources panel, where executed and unexecuted lines are marked in the margin. Source maps make bundled code readable.
  5. Use the page, then look againOpen the menu, search and scroll. Code that runs only now is a good candidate to load on interaction instead of on page load.
  6. Label every file by ownerYour own bundles go to the developers; ads, analytics, chat and testing tags go to whoever added them, usually through a tag manager.

Google’s Coverage panel guide also lets you switch between measuring per function and per block, and export the results. If you use a bundler such as webpack, Vite or Rollup, a bundle analyzer plugin shows which packages make up each file, which quickly reveals a date library, an icon set or a whole component library imported for one small use.

How to reduce unused JavaScript

Send each page only the code it needs to appear and respond, and load the rest when it is needed. In practice that means splitting bundles, importing less, loading features and widgets on interaction, and removing or delaying other companies’ tags.

Common causes and their fixes
What you see in the listWhy it is unusedThe fix
One big app or main bundleIt holds code for every page and feature, and this page uses a slice of it.Split by route and feature with dynamic import(), so each page loads its own chunk.
A vendor bundle of librariesWhole libraries are imported for one or two functions.Import only what you use, use smaller libraries, and let tree shaking drop unused exports.
Ads, analytics or session recordingThe tag ships its full feature set to every page.Remove tags nobody reads, limit them to the pages that need them, and start them after the page has loaded.
Chat, video or map widgetsThe full widget loads although few visitors open it.Show a simple button that looks like the widget and load the real one when someone taps it.
Plugin scripts on WordPress or ShopifyPlugins and apps load their scripts on every page.Remove unused plugins and apps, and load the rest only on the pages they serve.
Polyfills for old browsersCode that makes new features work in old browsers runs nowhere today.Build for the browsers your visitors use; Lighthouse reports this separately as Legacy JavaScript.

Split your own bundles

Code splitting means breaking one large file into smaller ones that load when needed. As the web.dev article on reducing JavaScript payloads with code splitting puts it, “Code splitting is a technique that seeks to minimize startup time.” Modern bundlers split automatically wherever your code uses a dynamic import:

// Before: the size guide code ships with every product page
import { openSizeGuide } from './size-guide.js';

// After: it downloads only when someone taps the button
button.addEventListener('click', async () => {
  const { openSizeGuide } = await import('./size-guide.js');
  openSizeGuide();
});

Frameworks build this in. Next.js and Nuxt split by page, so check that shared layouts and the custom app file do not import heavy components every page then carries; Target’s largest unused file was its Next.js _app bundle, the one that wraps every page. In React, Google’s audit page suggests that if you are not rendering on the server, you split bundles with React.lazy(); Next.js offers next/dynamic for the same job. Vue and Angular support lazy routes in their routers.

Import less

Tree shaking is the bundler’s ability to leave out exports you never import. It only works when the library is written as ES modules and you import named functions, so import { debounce } from 'lodash-es' beats import _ from 'lodash'. Check the bundle analyzer for libraries that appear once and weigh a lot, and replace them with a small function or a browser feature where you can: native date formatting, fetch and CSS animations cover much of what older libraries were added for.

Delay or drop other companies’ tags

For ads, analytics, session recording, A/B testing and chat, the question is less how to trim the code than whether each tag needs to load first. Make a list of every tag in your tag manager with its owner and the last time anyone used its data. Remove the ones nobody can name. Restrict the rest to the pages that need them, and fire them after the page has loaded or on the first interaction rather than at the top of the page. A chat widget can be a plain button that loads the real widget only when tapped. These changes need agreement from marketing as much as code from developers, so bring the Lighthouse list with you: it names each file and its cost.

Load scripts without blocking

Scripts that must stay should not hold up the first screen. Add defer to scripts in the head so the browser downloads them in parallel and runs them after reading the HTML, or async for independent tags. That does not reduce unused JavaScript, but it removes scripts from Lighthouse’s related warning, Eliminate render-blocking resources, and lets the main content appear sooner:

<script src="/js/app.js" defer></script>
<script src="https://example-analytics.com/tag.js" async></script>

On WordPress and Shopify

Google’s audit page advises WordPress owners to consider “reducing, or switching, the number of WordPress plugins loading unused JavaScript in your page.” Deactivate plugins you no longer use, then use a performance plugin’s script manager to stop the rest loading on pages that do not need them, such as a form plugin outside the contact page. On Shopify, uninstalling an app does not always remove its code from the theme, so search the theme files for leftover snippets after removing one.

Unused JavaScript usually appears with three other warnings: Minimize main-thread work, Reduce JavaScript execution time and Eliminate render-blocking resources. They describe the same scripts from different angles, so one round of fixes often clears several.

Minimize main-thread work adds up everything the browser did on its main thread while loading: running scripts, working out styles, laying out the page and painting it. On Target’s home page it came to 15.8 seconds, and on Wayfair’s to 11.8 seconds. Reduce JavaScript execution time is the scripting part of that, 11.5 and 8.3 seconds, with the files that took longest. Here the first file was not always the one with the most unused bytes: on Target, a script from client.px-cloud.net led the list, and on Wayfair, a chunk of its own build. Sending less JavaScript is the most direct way to bring both down, followed by breaking long tasks into smaller ones so the page can answer taps in between.

Eliminate render-blocking resources, now called Render-blocking requests, lists the stylesheets and scripts the browser must fetch before it shows anything. On both home pages the list was stylesheets, with an estimated 2,180 milliseconds of savings on Target and 1,170 on Wayfair. For scripts, defer and async fix it; for CSS, put the styles the first screen needs in the page and load the rest without blocking.

Before you change anything

  • You have run Lighthouse on a phone setting for home, category, product and checkout pages.
  • You have the list of files with unused bytes, and an owner for each.
  • You have recorded the page in Coverage while using its menus, search and forms.
  • You know which tags marketing, analytics and support still use.

After the fix

  • Lighthouse lists fewer files, or smaller savings, under Reduce unused JavaScript.
  • Total Blocking Time and Largest Contentful Paint went down across several runs.
  • Every feature you moved to load on demand still works on a slow connection.
  • Analytics and ads still record what the business relies on.

How to check the fix worked for real visitors

Run Lighthouse three to five times before and after, and compare the medians, because single runs vary. Then watch real-visitor data in the Chrome UX Report over the following four weeks, since that is what Google uses for page experience.

Lab tests such as Lighthouse load the page once, on a simulated phone and connection, so the numbers change from run to run, especially on pages full of ads that differ each time. Look for a clear drop in the estimated savings and in Total Blocking Time across several runs rather than one good score. The Chrome UX Report, shown at the top of PageSpeed Insights when your page has enough traffic, reports what real Chrome users experienced over the previous 28 days, including Interaction to Next Paint. Expect it to move gradually after a release.

Check accessibility and search at the same time, because script changes can break them. A menu that now loads on demand must still open with the keyboard, and content that used to arrive by JavaScript must still be in the page for search engines. Our website audit checklist covers speed, accessibility and search together, and the SEO audit example shows how speed findings sit beside search problems in a real report.

This is where UX Robot helps. A page audit, like the two behind this guide, measures the page with Lighthouse and the Chrome UX Report and has your own AI agent check it in a real browser, then lists every speed problem with the files that cause it, its estimated saving and the fix, beside the page’s accessibility, usability and search problems. The Free plan covers five page audits a month and Pro makes them unlimited. Enterprise audits whole journeys with your GA4, Search Console and Clarity data, sends issues to your tracker and reruns them on a schedule, so you can see the fix hold. Compare the plans.

Questions about unused JavaScript

Does unused JavaScript affect my PageSpeed score?

Not directly. Only the metrics count toward the score, but the time unused scripts take to download and run makes Largest Contentful Paint and Total Blocking Time worse, and those two make up more than half of it.

Can I just delete the unused code Lighthouse shows?

Usually not. Lighthouse only sees one page load, so code that looks unused may run when someone opens a menu or reaches another page. Load it later or on the pages that need it instead, and test each feature afterwards.

How do I reduce unused JavaScript from Google Tag Manager or Google Ads?

You cannot change Google’s own files, but you can choose which tags fire, on which pages and when. Remove old tags, limit the rest to the pages that need them, and use triggers that fire after the page has loaded.

How do I remove unused JavaScript in WordPress?

Deactivate plugins you do not use, then stop the remaining plugins loading their scripts on pages that do not need them, with a script manager in a performance plugin. Test forms, sliders and checkout after each change.

Is unused CSS the same problem?

It is a separate audit, Reduce unused CSS, with the same idea: styles the page does not use. Stylesheets block the first paint, so they delay the page even more directly than deferred scripts do.

Where do the Target and Wayfair figures come from?

From UX Robot page audits of each home page on a 390 by 844 pixel phone screen on November 26, 2026, with Lighthouse’s mobile test run by UX Robot’s server. They are one lab test each on a sales day, and the pages may have changed since.

Sources

  1. Reduce unused JavaScript, Lighthouse documentation, Chrome for Developers.
  2. Find unused JavaScript and CSS with the Coverage panel, Chrome DevTools documentation, Chrome for Developers.
  3. Lighthouse performance scoring, Chrome for Developers.
  4. Reduce JavaScript payloads with code splitting, web.dev.
  5. Optimize Interaction to Next Paint, web.dev, updated September 2, 2025.
  6. JavaScript, Web Almanac 2024, HTTP Archive, June 2024 crawl, updated January 16, 2026.
  7. UX Robot page audits of Target’s home page and Wayfair’s home page, mobile, November 26, 2026.

Put this guide to work

Check your own page in about a minute.

Type your page’s address and UX Robot shows how fast it is for real visitors, how accessible it is and what search engines see, free and without signing up.

Then your own AI agent can audit the whole page for usability and WCAG 2.2, five pages a month on the free plan. See the plans

How does your page do?

Check it free