Site AI Auditod Internet Solutions

How to Reduce Unused JavaScript and Speed Up Your Pages

19 sierpnia 2026Czas czytania: 8 minSzybkość strony
How to Reduce Unused JavaScript and Speed Up Your Pages

Short answer: Unused JavaScript is code that a page downloads but does not run during the visit. To reduce it, first measure it with the Coverage tab in Chrome DevTools or the “Reduce unused JavaScript” audit in PageSpeed Insights, then remove scripts nobody needs, load plugin and widget scripts only on pages that use them, delay non-essential third-party tools, and split large bundles so each page loads only its own code. Less JavaScript means faster loading and better responsiveness, especially on phones.

JavaScript is the most expensive kind of resource a page can load, byte for byte. An image only needs to be downloaded and decoded. A script has to be downloaded, parsed, compiled and executed, all on the browser’s main thread, which is also responsible for responding to taps and clicks. On a mid-range phone, the processing cost of a large bundle can easily exceed its download time. That is why speed tools single out unused JavaScript: it is pure cost with no benefit on the page where it loads.

Where unused JavaScript comes from

Hardly anyone writes unused code on purpose. It accumulates:

How to measure unused JavaScript

  1. PageSpeed Insights / Lighthouse. The “Reduce unused JavaScript” audit lists files with the most unused bytes and an estimated saving. It also shows whether a file belongs to your domain or a third party.
  2. Chrome DevTools Coverage tab. Open the Command Menu, choose “Show Coverage”, start recording and reload. Each file shows total bytes and unused bytes; red bars mark unused code. Interact with the page to see how much of the “unused” code is actually needed for menus or forms.
  3. Network panel filtered by JS. Sort by size to see the heaviest scripts and their origins. Group by domain to see how much comes from third parties.
  4. Performance panel. Record a load on a throttled CPU and look at “Scripting” time and long tasks, which shows the processing cost, not just the download.

Keep in mind that “unused during load” does not always mean useless. Code for a checkout button or a modal may run only after a click. Coverage is a guide for finding candidates, not a list of code to delete blindly.

Step 1: Remove what nobody needs

The most effective step is also the simplest: remove scripts that serve no current purpose.

Step 2: Load scripts only where they are used

Many scripts are needed somewhere, just not everywhere.

Step 3: Delay non-essential scripts

Some tools are needed on every page but not during the first seconds: chat widgets, feedback tools, some analytics and marketing scripts.

Step 4: Split and trim your own bundles

If your site uses a build process (common for custom themes, headless sites and web applications), the build can do a lot of the work:

Unused JavaScript and Core Web Vitals

MetricHow excess JavaScript affects it
Largest Contentful PaintBlocking scripts delay rendering; downloads compete with the main image for bandwidth
Interaction to Next PaintParsing and executing code keeps the main thread busy, so taps wait
Cumulative Layout ShiftScripts that inject content late can move the layout
Total Blocking Time (lab)Long tasks from script execution add directly to it

In practice, reducing JavaScript is the most reliable way to improve INP and Total Blocking Time, and it often helps LCP on mobile as well.

A simple JavaScript budget

Once you have cleaned up, the challenge is keeping it that way. Every new plugin, widget or marketing tool adds code, and nobody notices until the site feels slow again. A lightweight budget helps. Record the total JavaScript transferred and the Total Blocking Time for your home page and one typical content page today. Agree that any new tool must justify its cost, and check both numbers after each addition. Agencies can include the same numbers in monthly reports, so clients see the effect of the tools they ask for. The budget does not need to be strict; its value is that someone looks at the numbers before, not months after, a heavy script goes live.

What you usually cannot fix

Some unused JavaScript is out of your control. Payment providers, consent tools, and embedded services ship their own bundles, and you cannot trim them. What you can control is where and when they load. A payment script belongs on checkout, not on the home page. A video player belongs behind a click, not on page load. Speed tools will still list these files; judge them by whether the page needs them, not by the warning alone.

How Site AI Audit helps

Site AI Audit runs Google PageSpeed for mobile as part of every check and reports Core Web Vitals, page weight, compression and server response time. Heavy or unnecessary scripts show up in the speed findings through their effect on INP and page weight, with a plain-language explanation of what to change first. Paid plans include re-checks and weekly monitoring, so you notice when a new tag quietly slows the site down; see the plans.

Related reading

The bottom line

Unused JavaScript is the most expensive kind of waste on a web page. Measure it, then remove what nobody needs, load the rest only on pages that use it, delay what can wait and split your own bundles. Test interactive features after every change and measure again on a slow phone profile, where the improvement is most visible.

FAQ

What does “reduce unused JavaScript” mean?

It means the page downloads JavaScript that is not executed during loading. That code costs download and processing time without contributing to the page. The recommendation is to remove it, load it only where needed or delay it.

Is all unused JavaScript safe to remove?

No. Some code only runs after user actions, such as opening a menu or submitting a form, so it appears unused during load. Use the Coverage report as a list of candidates and test interactions before removing anything.

How much JavaScript is too much?

There is no single limit, but many sites load far more than they need. Watch the effect rather than the number: high Total Blocking Time, poor INP or long scripting time on a throttled phone profile indicate too much JavaScript for that page.

Can I reduce unused JavaScript from Google Analytics or other third parties?

You cannot change their code, but you can decide whether you need each tool, remove duplicates, and control where and when it loads. Removing one unnecessary third-party tag often saves more than any optimisation of your own code.

Do WordPress plugins cause unused JavaScript?

Often, because many plugins load their scripts on every page regardless of whether the feature is used there. Asset-management tools or small code changes can restrict them to relevant pages. Choosing plugins that load assets conditionally also helps.

#JavaScript performance#Mobile performance#Page speed#WordPress performance
Sprawdź swoją stronę — za darmo.Co poprawić na Twojej stronie — i od czego zacząć.
Zacznij za darmo
Internet Solutions

Więcej od naszego zespołu

Stworzone przez Internet Solutions. Wypróbuj nasze pozostałe produkty — każdy oszczędza czas na swój sposób.

internet-solutions.net ↗
Site AI Audit
Przegląd prywatności

Ta strona używa plików cookie, abyśmy mogli zapewnić Ci jak najlepsze wrażenia. Informacje z plików cookie są przechowywane w Twojej przeglądarce i pełnią funkcje takie jak rozpoznawanie Cię po powrocie na stronę oraz pomagają naszemu zespołowi zrozumieć, które sekcje strony są dla Ciebie najciekawsze i najbardziej przydatne.