Try it on your own data
Every report in this article is in the free plan. One snippet for web and apps, up to 10 sites.
Start freeTo remove unused JavaScript, record coverage in Chrome DevTools on each important route, then cut in a fixed order: delete dead code, stop loading page-specific scripts site-wide, split by route, lazy-load click-only code and defer the rest. Treat the Lighthouse audit as a lead, not a verdict, and confirm the gain with real-user p75 LCP and INP.
What you will learn
- Lighthouse flags files with over 20 KiB unused on one load; code for other routes or later clicks shows as unused too
- Remove first, then split and lazy-load, then defer; only removal cuts download, parse and compile work entirely
- Judge the change on field p75 LCP and INP for the same page and device mix, and watch script errors after each release
What does "remove unused JavaScript" mean?
"Remove unused JavaScript" (also shown as "Reduce unused JavaScript") is a Lighthouse and PageSpeed Insights audit. It lists script files that the browser downloaded during page load but did not execute, and Chrome's documentation says it flags every file with more than 20 KiB of unused code. The fix is not always deletion. Code can be unused because it is dead, because it belongs to another route, or because it only runs after a click, and each case has a different fix.
Unused code still costs something. The browser downloads it, parses it and compiles it, usually on the main thread that also has to respond to taps and clicks. The HTTP Archive's 2024 Web Almanac measured a median of 558 KB of JavaScript per mobile page and 613 KB per desktop page, and found a median of 206 KB of it, or 44% of bytes delivered, unused during page load on mobile.
The approach in this guide: treat the audit as a lead, not a verdict. Measure coverage per route, cut in a fixed order (remove, then split, then defer), and confirm the gain on real users rather than on one lab run. General speed fixes such as images, caching and server response time are ranked in how to speed up a website; this article covers the single JavaScript audit in depth.
Why is one Lighthouse run a lead, not a verdict?
The audit is useful, but its number describes one page load in one simulated environment. Three things it cannot tell you:
- Unused on load is not unused overall. Code that opens a modal, validates a form or draws a chart after a click shows as unused, because the click never happened in the lab. Deleting it breaks the feature.
- One URL is not the site. A single-page app often ships one bundle for every route. Code unused on the landing page may be the core of the dashboard route.
- Bytes saved is not time saved. Moving 80 KB off the critical path may cut Largest Contentful Paint a lot on a slow phone and not at all on a fast laptop. Only field data across your real device mix shows the effect.
So use the audit to find candidates, then answer two questions for each file: which routes need this code? and when does it need to run?
How do you find unused JavaScript per route?
Chrome DevTools has a Coverage panel built for this. The steps:
- Open DevTools, open the Command Menu (Ctrl+Shift+P or Cmd+Shift+P), type "coverage" and choose Show Coverage.
- Pick Per function or Per block in the panel's drop-down. Per block is finer and shows unused branches inside a function.
- Click the reload button in the panel. The page reloads while Coverage records which code runs.
- Do what a real visitor does on that route: scroll, open the menu, submit the form. Recording continues while you interact, so code those actions need moves from "unused" to "used".
- Stop recording and read the table: URL, type, total bytes, unused bytes and a usage bar. Click a row to see unused lines marked in the Sources panel.
- Repeat for every important route: landing page, product or pricing page, checkout or signup, and the logged-in app.
Write the results into a table with one row per script and one column per route. A script that is 90% unused on the landing page and 85% used in the app is a code-splitting candidate. A script that is unused on every route is a deletion candidate. If you have many routes, Chrome's documentation points to Puppeteer's coverage API to automate the same measurement.
Remove, split, defer or keep: which fix fits?
| What the code is | Signal in Coverage | Fix | Typical saving on the route |
|---|---|---|---|
| Dead code: old features, unused library exports | Unused on every route and after interaction | Remove it, or rely on tree shaking by importing only what you use | Full size of the dead code |
| Plugin or widget not used on this page | 100% unused on this route | Remove from this route: load it only on pages that use it | Full size on this route |
| Polyfills for browsers you no longer support | Mostly unused in modern browsers | Remove or serve only to old browsers | Most of the polyfill bundle |
| Code another route needs | Unused here, used on route B | Code-split by route; load the chunk on route B | Chunk size on this route |
| Code needed after a click | Unused on load, used after interaction | Lazy-load on interaction (dynamic import()) | Moves off the critical path |
| Third-party script needed but not urgent | Partly unused, not needed for first paint | Defer (defer attribute or load after the page is interactive) | Moves off the critical path, still downloaded |
| Framework runtime and code for the first view | Mostly used | Keep | None |
The order matters. Removing code is the only fix that cuts download, parse and compile work entirely. Splitting and lazy-loading move the cost to where it is needed. Deferring only changes timing. Start at the top of the table and stop when the field numbers are good.
| What the code is | Fix | Saving on the route |
|---|---|---|
| Dead code or unused exports | Remove or tree-shake | Full size |
| Plugin unused on this page | Load only where used | Full size on this route |
| Legacy polyfills | Remove or serve to old browsers | Most of the bundle |
| Code another route needs | Code-split by route | Chunk size |
| Code needed after a click | Lazy-load with import() | Off the critical path |
| Non-urgent third-party script | Defer | Off the critical path, still downloaded |
Work top to bottom and stop when field metrics reach the good thresholds.
Worked example: a 420 KB landing-page bundle
Sample data: a marketing site's landing page loads five scripts totalling 420 KB (uncompressed). Coverage on the landing route, with a scroll and a click on the main menu during recording, shows 256 KB unused: 256 ÷ 420 = 61%.
| Script | Size | Unused on landing | Unused share | Fix |
|---|---|---|---|---|
| Main app bundle | 220 KB | 110 KB | 50% | Code-split by route, landing keeps 140 KB |
| Chart library | 80 KB | 64 KB | 80% | Lazy-load on the dashboard route only |
| Polyfills | 45 KB | 41 KB | 91% | Remove; serve to legacy browsers only |
| Carousel plugin | 35 KB | 35 KB | 100% | Remove from this route |
| Chat widget | 40 KB | 6 KB | 15% | Keep, load with defer |
| Total | 420 KB | 256 KB | 61% |
Two details in the table matter. First, the chart library shows 16 KB as "used" on a page with no chart, because its initialization runs on import; Coverage cannot tell useful work from setup cost. Second, the main bundle cannot lose all 110 KB of its unused code. Splitting moves 80 KB to other routes, leaving 140 KB, of which 30 KB is still unused on landing (shared utilities, error handlers).
After the changes: the landing page downloads 140 KB of main bundle plus the 40 KB deferred widget = 180 KB, of which 36 KB (20%) is unused. Removed from the landing route: 80 + 80 + 45 + 35 = 240 KB, a 57% cut. Lighthouse will still list the main bundle if its unused part exceeds 20 KiB, and that is acceptable: the last 30 KB costs more engineering time than it saves.
Unused JavaScript on the landing page
sample, KB unused of KB loadedIn what order should you cut?
A fixed order keeps the work small and the risk low:
- Delete dead code and unused dependencies. Search the codebase for imports nobody calls; check whether a 70 KB library is used for one function you could write in ten lines.
- Stop loading page-specific plugins site-wide. Many sites include every plugin's script on every page. Attach each script to the pages that use it.
- Drop polyfills for browsers you no longer support, or serve them through a separate legacy bundle.
- Split by route, then lazy-load interaction-only code with dynamic imports.
- Defer third-party scripts that are not needed for the first view.
- Re-run Coverage on every route and run a smoke test of each feature you touched.
Ship each step separately. If field LCP improves after step 2, you know which change paid off, and a bug can be traced to one deployment.
How do you confirm the gain on real users?
Lab runs vary from run to run and use one device profile. Core Web Vitals are judged on field data: Google's guidance is to measure at the 75th percentile of page loads, segmented by mobile and desktop, with "good" thresholds of LCP ≤ 2.5 seconds, INP ≤ 200 milliseconds and CLS ≤ 0.1. See Web Vitals for what each metric measures and website performance metrics for the wider set.
Sample data, the landing page above, 14 days before and 14 days after the release:
| Metric (p75, landing page) | Before | After | Change | Threshold |
|---|---|---|---|---|
| Largest Contentful Paint | 3.1 s | 2.6 s | −0.5 s (−16%) | Good ≤ 2.5 s |
| Interaction to Next Paint | 280 ms | 190 ms | −90 ms (−32%) | Good ≤ 200 ms |
| Page loads sampled | 18,400 | 17,900 | ||
| Mobile share of loads | 62% | 61% |
Read it with three rules:
- Compare like with like. Same page, same length of period, similar device mix. A campaign that brought more desktop visitors can make p75 look better with no code change.
- INP often moves more than LCP. Less script to parse and run means a less busy main thread when the visitor taps. Here INP crossed into "good" while LCP still sits just above 2.5 seconds, so the next fix for LCP is probably not JavaScript (check the image and server response).
- Wait for enough samples. Percentiles on a page with a few hundred loads jump from day to day. Two weeks per side is a reasonable floor for a page with modest traffic.
What can break when you remove JavaScript?
- Features used only after interaction. The most common breakage. Test every button, form and menu on routes you touched.
- Code used by a small share of browsers. A polyfill removed for modern browsers may still be needed by an embedded browser inside another app.
- Order-dependent scripts. A deferred script that another inline script expects to exist will throw an error.
- Tag-manager and consent logic. Removing or deferring a tag can change when analytics or consent banners load; check that measurement still fires.
Watch script errors for a few days after each release. A spike right after a deploy is the fastest signal that something needed was removed.
How do you check the result in TapCub?
TapCub does not analyse your bundles or run Lighthouse; Coverage and your build tools do that. TapCub's part is the real-user check after each release, using the landing-page example above:

- Mark the release. Add an entry in Configuration › Annotations on the day each step ships ("removed carousel and polyfills from landing"), so the trend line shows where each change landed.
- Read field metrics for the route. Open Monitoring › Performance, set cards to P75 and break down by page. Compare the landing page's Largest Contentful Paint and Interaction to Next Paint for 14 days before and after the annotation. The page has no previous-period comparison, so switch the date range to read each side.
- Check the device mix. In the same breakdown, switch the dimension to device to confirm mobile and desktop moved in the same direction, rather than a traffic-mix change producing the gain.
- Watch for breakage. Open Monitoring › Errors. Error rate there is script errors divided by pageviews; a new error group that first appears on the release day, on the route you changed, usually means removed code was still needed. Expand it to see the page and device.
- Set a guard. In All-platform analytics › Operations › Monitors, add a rule on the built-in
error_ratemeasure and dry-run it; the dry run reports how many times it would have fired in the last 30 days, so you can pick a threshold that is quiet on normal days.
Performance metrics are reported by the visitor's browser, so pages where the script is blocked have no samples.
FAQ
How do I remove unused JavaScript?
Record coverage in Chrome DevTools for each important route while using the page normally. Then, in order: delete dead code and unused dependencies, stop loading page-specific plugins site-wide, drop unneeded polyfills, split bundles by route, lazy-load code that only runs after a click, and defer non-urgent third-party scripts. Confirm the result with field data at the 75th percentile.
Why does Lighthouse say "reduce unused JavaScript"?
Because at least one script file loaded during the test has more than 20 KiB of code that did not execute during page load. It does not mean the code is useless. It may belong to another route or run after interaction. Use the audit as a list of candidates and check each file with the Coverage panel.
Does unused JavaScript affect SEO?
Indirectly. Unused script adds download, parse and compile work, which can slow Largest Contentful Paint and Interaction to Next Paint, and Core Web Vitals are part of the page experience signals Google uses. The effect depends on how much the code delays the main thread on real devices, which is why field data matters more than the audit score.
Is it safe to remove unused JavaScript?
Removing dead code is safe; removing code that is only "unused on load" is not. Coverage marks click handlers, form validation and chart code as unused if you did not trigger them during recording. Interact with the page while recording, test every feature on routes you changed, and watch script errors after each release.
What is a good amount of unused JavaScript?
There is no official target beyond the audit's 20 KiB per-file threshold. Some unused code is normal: shared utilities and error handling rarely run on every page. In the example, cutting the landing page from 61% to 20% unused moved field INP into the good range. Stop when field metrics are good, not when the audit is empty.
Sources
- Chrome for Developers: Remove unused JavaScript (Lighthouse): 20 KiB per-file threshold, code splitting, Puppeteer coverage (checked 2026-11-28)
- Chrome DevTools: Find unused JavaScript and CSS with the Coverage panel (checked 2026-11-28)
- HTTP Archive Web Almanac 2024: JavaScript: median 558 KB mobile / 613 KB desktop; 206 KB (44%) unused on mobile (checked 2026-11-28)
- web.dev: Web Vitals: 75th percentile rule and good thresholds (checked 2026-11-28)
Was this article helpful?
We use your answers to fix and expand this page.
Couldn’t send. Please try again in a minute.
Thanks for the feedback. We’ll use it to improve this page.You’ve already sent feedback on this page. Thanks.

Product Experience Specialist
Writes about product experience, practical workflows, and growth, turning complex processes into clear steps for everyday decisions.



