SEO & Speed Optimization

Reduce Unused JavaScript: Fix This PageSpeed Warning and Speed Up Your Site

"Reduce unused JavaScript" is one of the most common PageSpeed warnings. Here's how to find the code you don't need and stop loading it.

In this article · 9 sections
  1. Step 1: Find what's unused
  2. Step 2: Remove what you don't need
  3. Step 3: Load scripts only where needed
  4. Step 4: Defer and delay
  5. Step 5: Code splitting (for apps)
  6. Step 6: Replace heavy features with lighter ones
  7. Step 7: Minify and compress
  8. Measure the impact
  9. FAQs
  10. Can I remove all unused JavaScript?
  11. Will removing scripts break my site?

PageSpeed Insights often shows "Reduce unused JavaScript" with a list of large scripts. Every kilobyte of JavaScript must be downloaded, parsed and executed, which is slow on budget phones. Here's how to reduce unused JavaScript without breaking your site.

Step 1: Find what's unused

  • PageSpeed Insights: lists scripts with estimated unused bytes
  • Chrome DevTools → Coverage tab (Ctrl+Shift+P → "Show Coverage"): reload the page and see how much of each file runs
  • Network tab: sort by size to find the heaviest scripts

Step 2: Remove what you don't need

Common culprits: - Old libraries (jQuery plugins, sliders, animation libraries) no longer used - Page builder scripts loaded on every page - Plugins for features you removed - Duplicate libraries (two versions of jQuery, multiple icon libraries) - Forgotten tracking tags from old campaigns

Deleting is the biggest win.

Step 3: Load scripts only where needed

  • Load the booking calendar script only on the booking page
  • Load gallery/lightbox only on gallery pages
  • In WordPress, use asset management plugins or code to dequeue scripts on pages that don't need them

Step 4: Defer and delay

<script src="/js/main.js" defer></script>
  • defer for your own scripts
  • Delay non-essential third-party scripts until user interaction (chat, social widgets). See third-party scripts

Step 5: Code splitting (for apps)

Bundlers (Vite, webpack) can split code so each page loads only its part. Dynamic import() loads features when needed.

Step 6: Replace heavy features with lighter ones

  • CSS instead of JavaScript for simple animations and accordions (<details> element)
  • Native lazy loading instead of lazy-load libraries
  • Simple WhatsApp link instead of a heavy chat widget
  • Lightweight icon SVGs instead of icon fonts. See SVG for web design

Step 7: Minify and compress

Minification and Brotli/GZIP compression reduce transfer size. See HTTP/2, HTTP/3 and Brotli.

Measure the impact

Re-run PageSpeed Insights and watch Total Blocking Time and INP improve.

FAQs

Can I remove all unused JavaScript?

Not entirely. Some code runs only after interactions. Aim to remove large, clearly unnecessary chunks.

Will removing scripts break my site?

It can, so test on a staging copy first. See staging sites.

Joboo Web audits and trims JavaScript as part of speed optimisation. Ask us.

Share this article

Joboo Web

Web design, SEO & digital marketing team · Ludhiana, Punjab

Joboo Web has helped Indian businesses grow online since 2019 — building fast websites and running SEO, Google Ads and social campaigns for clients in 80+ cities. About us →

Keep reading

💬