Unused JavaScript is script code a page downloads but does not run during that visit, such as a whole library loaded for one small feature, or code for widgets that are not on the page. The browser still has to fetch it and often parse and compile it, so it slows loading and can make the page slower to respond to taps and clicks.
What is unused JavaScript? #
Modern sites bundle many scripts together. A theme ships code for every option it offers. A plugin adds a file to every page, even pages where it does nothing. A developer imports a full date library to format one date. Tag managers pile on chat widgets, heatmaps and old marketing tags. Any of that code that never runs on a given page is unused on that page.
It is related to, but not the same as, unused CSS. Unused styles mostly delay the first paint. Unused scripts delay the paint too, if they block, and then keep the main thread busy. That second cost is why scripts deserve more care.
Why does it cost more than other files? #
web.dev’s guide to tree shaking calls JavaScript an expensive resource to process. After download, it must be parsed, compiled and run. An image only needs to be decoded. The guide says that, byte for byte, this makes JavaScript costlier than other resource types. It also notes that compression only shrinks the transfer: 900 KB of decompressed script is still 900 KB for the parser and compiler. So gzip or Brotli and minification help, but they do not remove the work.
web.dev’s remove unused code guide links the cost to Core Web Vitals: extra script adds main-thread work that can hurt Interaction to Next Paint, and it can slow Largest Contentful Paint by competing for bandwidth. Long tasks also show up as Total Blocking Time in lab tests.
Why does it matter for search? #
For users, it is a page speed problem first. For crawlers, there is a second angle. Google’s JavaScript SEO basics describe 3 steps for script-heavy pages: Google crawls them, renders them, then indexes them. Pages wait in a render queue, which can take a few seconds or longer, before headless Chromium runs the scripts. Google still recommends rendering on the server, or pre-rendering, since that is quicker for people and bots, and some bots never run scripts. Heavy, mostly unused bundles make rendering slower and more fragile. See JavaScript SEO and client-side vs server-side rendering.
One warning: never block your script files in robots.txt to hide the bloat. Google says it will not render JavaScript from blocked files.
Why does it matter for AI answers? #
Many AI crawlers read the HTML they are sent and may not run scripts. If your product name, price or answer only appears after a large bundle runs, those readers may see an empty shell. Trimming unused code does not fix that on its own. Putting the real content in the first HTML does. The two jobs go together: once the content is server-rendered, the script that is left can be smaller and load later. Our JavaScript SEO Checker shows what bots that do not run JavaScript would miss.
How does Lighthouse flag it? #
Chrome’s page for the Reduce unused JavaScript audit says Lighthouse flags every script file with more than 20 KiB of unused code. You see it in PageSpeed Insights too. The saving is an estimate for one load of one page, before anyone clicks anything.
How do I find it? #
- In Chrome DevTools, open the Coverage tab with the Show Coverage command and click Reload.
- Use the page as a visitor would: open the menu, add to basket, play the video. Coverage keeps recording.
- Filter to JavaScript and sort by unused bytes. Grey in the bar is unused, green is used.
- Read the file addresses. They usually name the plugin, theme or outside service.
- For your own bundles, a bundle analyser shows a map of which libraries make up each file. web.dev names tools for webpack, Parcel and Rollup.
How do I fix it? #
- Remove what you do not use. web.dev puts it plainly: if you are not using a library, remove it. The same goes for old tags in Google Tag Manager.
- Load plugins only where needed. Chrome’s audit advice for WordPress is to cut or swap plugins that load unused JavaScript. For Drupal it says to attach libraries only to the pages or components that use them.
- Import only the parts you need. Many libraries come in pieces. Import the piece, not the whole package.
- Split the bundle. web.dev’s code splitting guide says to send only what the first view needs and lazy load the rest. Its example loads a module with
import()only when a form is submitted. - Let the bundler shake the tree. Tree shaking drops exports nothing imports. web.dev says it works with ES module
importandexport, and is harder with CommonJS. - Do not block the parser. Scripts that must stay can often use async or defer.
MDN’s page on dynamic import() adds a balance: use it only when needed. The static form is better for code needed at the start, and works more readily with tree shaking.
Common mistakes #
- Testing without clicking. Code for the basket looks unused until someone adds a product.
- Deleting tracking by accident. Check conversion tracking still fires after you remove tags.
- Lazy loading what the first screen needs. If the main image or menu waits on a split chunk, the page gets slower.
- Ignoring outside scripts. Chat, reviews and video embeds are often the largest files. Load them on click.
- Measuring once. Lab scores vary. Compare several runs, and watch field data over weeks.
A worked example #
A small online shop has a product page that loads 1.1 MB of script. These numbers are made up to show the idea.
| Script | Unused on load | Fix |
|---|---|---|
| Theme bundle with every slider and gallery | 70% | Split by page type |
| Chat widget | 95% | Load after a click on “Chat” |
| Old A/B test tag | 100% | Remove from the tag manager |
| Date library used for one date | 90% | Import one function or use the built-in date format |
The shop then tests a product, the basket and checkout on a phone, checks that orders still record in analytics and runs the audit again.
How to check it #
- Our JavaScript SEO Checker shows what bots that do not run scripts would miss on a page.
- Our Tech Stack Checker lists the frameworks and plugins a page loads, and the Tracking Checker lists the tags.
- Our Page Speed Checker is coming soon.
- Shrink a small hand-written file with our JavaScript Minifier.
- Inside URSY Pro, our JavaScript rendering check (Pro) and Real user speed (Pro) will track it over time.
Questions #
Is all unused JavaScript bad? #
No. Some code is there for later clicks. The goal is to stop it blocking the first view, not to reach zero.
Does a CDN fix it? #
A CDN speeds up the download. The parse and compile work stays the same.
Can a plugin remove it for me? #
Some speed plugins delay scripts until the visitor interacts. That can help, but test that menus, forms and checkout still work.
Related words #
Sources #
- Chrome for Developers: Reduce unused JavaScript, checked 25 November 2026
- Chrome for Developers: Coverage tab, checked 25 November 2026
- web.dev: Remove unused code, checked 25 November 2026
- web.dev: Reduce JavaScript payloads with code splitting, checked 25 November 2026
- web.dev: Reduce JavaScript payloads with tree shaking, checked 25 November 2026
- Google Search Central: JavaScript SEO basics, checked 25 November 2026
- MDN: import(), checked 25 November 2026
Updated 25 November 2026 by URSY.
Cite this page: Unused JavaScript. URSY. Updated 25 November 2026. https://ursy.com/wiki/unused-javascript/ · Section links
Tools for this
- LiveJavaScript SEO Checkerwhat bots that don't run JavaScript missRun the check →
- LiveAI Readiness Checkeris your site ready for ChatGPT, Gemini, Claude? Score + fixesRun the check →
- LiveAI Bot Checkerwhich AI bots your robots.txt lets inRun the check →
- LiveRobots.txt Checker + Generatortest any address against your rules, or write new onesRun the check →
- LiveSchema Markup CheckerRun the check →
- ProJavaScript rendering checkWhat bots that don't run JavaScript missIn URSY Pro →