Skip to main content
KadiCache
Lighthouse: unused-javascript · TBT & INP10 min read1,065 wordsVerified 2026-11-23

How to Fix “Reduce unused JavaScript” in WordPress (GTM, Pixels, YouTube & Plugins)

Google Tag Manager, Meta Pixel, YouTube embeds, reCAPTCHA, and page-builder bundles routinely ship 600 KB to 1.8 MB of unused JavaScript on initial mobile load. Clear them cleanly in KadiCache Free Core without breaking tracking or forms.

Reduce unused JavaScript (unused-javascript) WordPress optimization diagram
0.000 Layout Shift7 Sections✓ Verified
Lighthouse Audit ID
unused-javascript
Metrics Affected
TBT · INP · LCP
KadiCache Solution Tier
Free Core
3-Step Quick Action Plan (Schema HowTo)
STEP 01
Enable Delay JavaScript Until Interaction

Open WP Admin -> KadiCache -> CSS & JavaScript and set JavaScript Execution to Delay Until Interaction to hold non-essential bundles off initial load.

STEP 02
Replace Heavy YouTube Iframes With Click-to-Play Previews

Open WP Admin -> KadiCache -> Lazyload and enable Replace YouTube iframes with preview image to eliminate ~840 KB–1.2 MB of unused base.js per video.

STEP 03
Trim Legacy WordPress & Contact Form 7 Scripts

In WP Admin -> KadiCache -> Bloat Removal, enable Disable WordPress Emojis, Disable oEmbeds, Disable jQuery Migrate, and Conditional Contact Form 7 Assets.

WP Admin -> KadiCache -> CSS & JavaScript (Defer & Delay JS)
MODULE TBT & INP · 2X RETINA
JavaScript Minification, Defer, and Delay execution controls with automatic jQuery and WooCommerce safeguards.2880×1840 WebP
⚡ Executive Summary · 30-Second Spec100% Code-Verified
WP Admin Path
WP Admin -> KadiCache -> CSS & JavaScript + Lazyload + Bloat Removal
Measured Impact
800 KB–2.2 MB Unused Initial JS Eliminated · 100% Free Core
DevTools Proof Marker
Lighthouse ID: unused-javascript
  • Lighthouse tracks JavaScript byte execution via V8 Profiler.startPreciseCoverage during initial load and flags scripts carrying >= 20 KiB of unexecuted code.
  • Unlike dead CSS inside your own theme, 75%–90% of unused JavaScript on WordPress comes from external third-party domains (googletagmanager.com, youtube.com, connect.facebook.net, gstatic.com/recaptcha, chat SDKs) whose source code you cannot edit or tree-shake!
  • Byte-for-byte, unused JavaScript is far costlier than unused CSS or images because mobile CPUs must decompress, parse, AST-compile, and execute JS on the main thread—inflating TBT (30% weight) and INP.
  • 100% Free Core Solution: Combine Delay JS Until Interaction, YouTube srcdoc Preview Facade, Smart Cart Fragments, and Bloat Removal.
Table of Contents (7 sections)

Why You Cannot "Tree-Shake" Most Unused JavaScript in WordPress#

In a custom Webpack/Vite React application, developers fix Reduce unused JavaScript by splitting bundles with dynamic import(). On a real commercial WordPress or WooCommerce site, look at the actual URLs listed under Reduce unused JavaScript in PageSpeed Insights:

Flagged Script in PageSpeed InsightsTypical Unused BytesWhy You Cannot Edit the File Directly
www.youtube.com/s/player/.../base.js~620 KB – 880 KB unusedHosted on Google’s servers; loaded automatically by every YouTube <iframe> even when nobody clicks Play!
www.googletagmanager.com/gtm.js & gtag/js~110 KB – 280 KB unusedHosted by Google; contains tag firing rules, ecommerce listeners, and consent logic unused during initial paint
connect.facebook.net/.../fbevents.js & TikTok / Klaviyo~90 KB – 240 KB unusedThird-party ad/CRM SDKs shipping full form-scraping and retargeting modules
www.gstatic.com/recaptcha/releases/.../recaptcha__en.js~180 KB – 260 KB unusedContact Form 7 or WPForms loading Google reCAPTCHA v3 on every blog post even where no form exists!
Elementor frontend.min.js, swiper.min.js & Theme Bundles~85 KB – 210 KB unusedVendor plugin files overwritten on every WordPress plugin update

Because you cannot rewrite Google’s base.js or gtm.js, the engineering solution on WordPress is preventing non-essential scripts from downloading and executing during initial page render—loading them strictly when needed or upon first user interaction!

FIG 01Activating Delay Until Interaction inside WP Admin -> KadiCache -> CSS & JavaScriptZoom 2x

The 4-Part KadiCache Free Core Fix for unused-javascript#

Every tool required to pass Reduce unused JavaScript ships inside 100% Free Core:

1. Replace Embedded YouTube Players With srcdoc Previews (-840 KB+ Per Video)#

Open WP Admin -> KadiCache -> Lazyload and toggle ON Replace YouTube iframes with preview image (MediaLazyOptimizer.php). Instead of downloading 1 MB of YouTube player JavaScript on page load, KadiCache renders an instant, accessible thumbnail preview (0 KB JS)—eliminating base.js from your PageSpeed report completely while respecting GDPR consent plugins (Backgrounds & YouTube Guide)!

2. Enable Delay JavaScript Until Interaction (DelayJsOptimizer.php)#

Open WP Admin -> KadiCache -> CSS & JavaScript and select Delay Until Interaction (Delay JS Guide):

  • GTM (gtm.js), GA4, Meta Pixel, TikTok, Hotjar/Clarity, live chat widgets, and non-critical plugin scripts are held off the network and CPU until the visitor scrolls, taps, moves the mouse, or presses a key.
  • Built-in DelayScriptClassifier.php and ConsentScripts.php automatically protect checkout gateways, anti-bot challenges (Turnstile / reCAPTCHA on form pages), WooCommerce galleries, and GDPR consent banners so nothing breaks.
  • Critical custom scripts opt out effortlessly via data-kadicache-no-delay or Delay JavaScript Exclusions.
FIG 02Eliminating ~1 MB of unused YouTube player JavaScript per embedded video inside WP Admin -> KadiCache -> LazyloadZoom 2x

3. Strip Global Core & Form Bloat (Bloat Removal + Conditional Loading)#

Open WP Admin -> KadiCache -> Bloat Removal (Bloat & Heartbeat Guide) and click Apply Recommended Preset:

  • Removes wp-emoji-release.min.js, wp-embed.min.js, frontend jquery-migrate.min.js, and frontend heartbeat.min.js.
  • Conditional Contact Form 7 Assets (ContactForm7.php): Stops Contact Form 7 from enqueuing form scripts on pages that contain no form!
  • Smart WooCommerce Cart Fragments (Commerce & Smart Cart): Stops cart-fragments.min.js from firing uncached /?wc-ajax=get_refreshed_fragments XHR calls on empty-cart guest sessions (WooCommerce Caching Guide).

4. Audit Retired Containers & Plugins Quarterly (Manual Hygiene)#

Even with Delay JS active, run a quick quarterly check inside Google Tag Manager and WP Admin -> Plugins:

PHPManual PHP Pattern: Dequeue a Heavy Plugin Script Outside Its Target Page
// Example: Only allow a heavy store-locator map SDK on '/find-a-store/'
add_action('wp_enqueue_scripts', static function (): void {
    if (!is_page('find-a-store')) {
        wp_dequeue_script('heavy-mapbox-store-locator');
    }
}, 100);

How Much Byte & CPU Savings Each Action Delivers on Mobile#

When troubleshooting a heavy WooCommerce storefront or agency marketing site, prioritize the biggest byte offenders in Chrome DevTools Coverage (JS) first:

Typical WordPress JS OffenderInitial Unused JS RemovedMain-Thread TBT SavedKadiCache Control
Embedded YouTube <iframe> (base.js)~840 KB per video380 – 650 msLazyload -> Replace YouTube iframes with preview image
GTM + GA4 + Meta + TikTok + Clarity~420 – 780 KB320 – 740 msCSS & JS -> Delay Until Interaction
Intercom / Crisp / Zendesk / Tidio Chat~260 – 540 KB180 – 410 msCSS & JS -> Delay Until Interaction
Global Contact Form 7 + reCAPTCHA v3~210 – 290 KB140 – 260 msBloat Removal -> Conditional CF7 + form-page-only Turnstile/reCAPTCHA
WP Emoji + oEmbed + jQuery Migrate~32 KB25 – 55 msBloat Removal -> Apply Recommended Preset

Notice how combining just those Free Core switches routinely removes 1.4 MB+ of unused JavaScript from initial mobile page load without touching a single theme template! Even better, KadiCache replays interactive UI scripts ahead of background analytics tags the instant a visitor taps or scrolls, keeping Interaction to Next Paint (INP) crisp (<= 80 ms) across mobile product pages and mega-menus.

“Reduce unused JavaScript” — Frequently Asked Questions

Does Minify JavaScript fix the “Reduce unused JavaScript” warning?
Minifying JS strips comments and whitespace (~10–18% smaller files, passing the Unminified JavaScript audit), but it does not remove unused functions inside gtm.js or base.js. Passing Reduce unused JavaScript requires delaying non-critical scripts, replacing YouTube iframes with facades, and removing unneeded global scripts.
Is Delay JavaScript Until Interaction really 100% free in KadiCache Core?
Yes! Unlike competing plugins that lock Delay JS or YouTube facades behind paid tiers, KadiCache includes Defer JS, Delay JS Until Interaction, jQuery dependency guards, WooCommerce cart/gallery safeguards, and the YouTube preview facade in 100% Free Core.
Will Delay JavaScript hurt Google Search SEO indexing of my content?
Never on server-rendered WordPress themes! Your headings, body copy, product descriptions, internal links, and JSON-LD schema are already present in the cached PHP HTML response—Googlebot reads 100% of your content without needing third-party JS.
Why did Chrome DevTools Coverage show 45% unused JS inside jquery.min.js when a script needed jQuery?
jQuery is a general-purpose library shipping AJAX, animations, Deferreds, and DOM traversal—any single page typically calls ~50% of its methods. At ~30 KB gzipped, deferred jquery.min.js has negligible impact once heavy third-party bundles (GTM, YouTube, chat) are delayed.
What if delaying JS causes my above-the-fold hero slider to look unstyled until I touch the screen?
Either enable Cloud Pro’s Zero-CLS Layout Stability (which holds delayed sliders in their exact visual dimensions before JS runs!) or exclude just that slider’s initialization script inside Delay JavaScript Exclusions.
Verified WordPress Fix · unused-javascript
Clear “Reduce unused JavaScript” without breaking Elementor or WooCommerce.
E-E-A-T Source Verified

Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.

apps/wordpress-plugin/src/Optimization/DelayJsOptimizer.phpapps/wordpress-plugin/src/Optimization/MediaLazyOptimizer.phpapps/wordpress-plugin/src/Optimization/WordPressCleanup.phpapps/wordpress-plugin/src/Integrations/Plugins/ContactForm7.php
Connected Topical Cluster · Continue Deepening Your Setup