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.

Open WP Admin -> KadiCache -> CSS & JavaScript and set JavaScript Execution to Delay Until Interaction to hold non-essential bundles off initial load.
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.
In WP Admin -> KadiCache -> Bloat Removal, enable Disable WordPress Emojis, Disable oEmbeds, Disable jQuery Migrate, and Conditional Contact Form 7 Assets.
- Lighthouse tracks JavaScript byte execution via V8
Profiler.startPreciseCoverageduring initial load and flags scripts carrying>= 20 KiBof 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) andINP. - 100% Free Core Solution: Combine Delay JS Until Interaction, YouTube
srcdocPreview Facade, Smart Cart Fragments, and Bloat Removal.
Table of Contents (7 sections)
- Why You Cannot "Tree-Shake" Most Unused JavaScript in WordPress
- The 4-Part KadiCache Free Core Fix for unused-javascript
- 1. Replace Embedded YouTube Players With srcdoc Previews (-840 KB+ Per Video)
- 2. Enable Delay JavaScript Until Interaction (DelayJsOptimizer.php)
- 3. Strip Global Core & Form Bloat (Bloat Removal + Conditional Loading)
- 4. Audit Retired Containers & Plugins Quarterly (Manual Hygiene)
- How Much Byte & CPU Savings Each Action Delivers on Mobile
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 Insights | Typical Unused Bytes | Why You Cannot Edit the File Directly |
|---|---|---|
www.youtube.com/s/player/.../base.js | ~620 KB – 880 KB unused | Hosted 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 unused | Hosted 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 unused | Third-party ad/CRM SDKs shipping full form-scraping and retargeting modules |
www.gstatic.com/recaptcha/releases/.../recaptcha__en.js | ~180 KB – 260 KB unused | Contact 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 unused | Vendor 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!
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.phpandConsentScripts.phpautomatically protect checkout gateways, anti-bot challenges (Turnstile/reCAPTCHAon form pages), WooCommerce galleries, and GDPR consent banners so nothing breaks. - Critical custom scripts opt out effortlessly via
data-kadicache-no-delayor Delay JavaScript Exclusions.
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, frontendjquery-migrate.min.js, and frontendheartbeat.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): Stopscart-fragments.min.jsfrom firing uncached/?wc-ajax=get_refreshed_fragmentsXHR 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:
// 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 Offender | Initial Unused JS Removed | Main-Thread TBT Saved | KadiCache Control |
|---|---|---|---|
Embedded YouTube <iframe> (base.js) | ~840 KB per video | 380 – 650 ms | Lazyload -> Replace YouTube iframes with preview image |
| GTM + GA4 + Meta + TikTok + Clarity | ~420 – 780 KB | 320 – 740 ms | CSS & JS -> Delay Until Interaction |
| Intercom / Crisp / Zendesk / Tidio Chat | ~260 – 540 KB | 180 – 410 ms | CSS & JS -> Delay Until Interaction |
| Global Contact Form 7 + reCAPTCHA v3 | ~210 – 290 KB | 140 – 260 ms | Bloat Removal -> Conditional CF7 + form-page-only Turnstile/reCAPTCHA |
| WP Emoji + oEmbed + jQuery Migrate | ~32 KB | 25 – 55 ms | Bloat 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?
Is Delay JavaScript Until Interaction really 100% free in KadiCache Core?
Will Delay JavaScript hurt Google Search SEO indexing of my content?
Why did Chrome DevTools Coverage show 45% unused JS inside jquery.min.js when a script needed jQuery?
What if delaying JS causes my above-the-fold hero slider to look unstyled until I touch the screen?
Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.
See why cutting unused JS lifts your PageSpeed score by +20 to +30 points.
Tame CPU script evaluation and compilation time (bootup-time).
Copy-paste exclusion patterns for menus, sliders, and analytics.
Prevent delayed carousels and galleries from jumping when JS wakes up.