Delay JavaScript Until Interaction & Ready-to-Use Exclusions
Cut mobile Total Blocking Time toward 0 ms with built-in WooCommerce gallery/payment/consent safeguards, data-kadicache-no-delay opt-outs, and copy-paste plugin exclusions.
- Holds non-essential third-party and theme scripts inert (
type="text/plain") until the visitor’s first scroll, tap, click, keypress, or pointer move (DelayJsOptimizer.php). - Automatically protects WooCommerce product galleries (
wc-single-product,zoom,flexslider,photoswipe), Stripe/PayPal, Turnstile/reCAPTCHA/hCaptcha, Cookiebot/OneTrust/Complianz/CookieYes, and TranslatePress/WPML/Weglot/GTranslate. - Guards entrance-animation classes (
elementor-invisible,data-aos,data-sal) and preloaders so above-the-fold sections never remain invisible before touch. - Supports surgical script URL, script ID, inline keyword,
data-kadicache-no-delayattribute, and page-path exclusions plusKeep delaying scripts for shoppers.
How Delay Until Interaction Unlocks 95–100 Mobile PageSpeed Scores#
Even when scripts carry defer, mobile browsers still download, parse, compile, and execute all of them right after HTML parsing—right inside Google Lighthouse’s measurement window! If Google Tag Manager, Meta Pixel, Hotjar, Intercom/Crisp live chat, YouTube APIs, and 15 Elementor widget scripts execute 850 ms of JavaScript tasks during initial load, Lighthouse penalizes Total Blocking Time (TBT) heavily and drops your mobile score into the 50s or 60s.
Delay Until Interaction (DelayJsOptimizer.php) changes when non-essential scripts run: during initial paint, non-critical scripts remain completely inert (type="text/plain"), consuming 0 bytes of network bandwidth and 0 ms of main-thread CPU. The instant the visitor touches the screen, scrolls, clicks, presses a key, or moves the mouse (or when an optional fallback timeout fires), KadiCache replays UI scripts smoothly ahead of low-priority analytics beacons.
What KadiCache Protects Automatically (No Manual Exclusions Needed!)#
DelayScriptClassifier.php, ConsentScripts.php, and DelayJsOptimizer.php automatically recognize and protect critical interactive scripts so you do not need to paste massive boilerplate exclusion lists:
| Protected Category | Built-In Handles & Domains Guarded Automatically | Why It Stays Immediate |
|---|---|---|
| WooCommerce Product Galleries | wc-single-product, zoom, flexslider, photoswipe, photoswipe-ui-default | Shoppers can swipe photos & tap variation swatches on first touch |
| Cart & 6 Wishlist Plugins | WooCommerce mini-cart fragments + WPC, YITH, TI, WCBoost, QODE & MoreConvert wishlists | Header cart & wishlist badge counts stay accurate without waking all JS |
| Payments & Anti-Bot SDKs | Stripe, PayPal, Cloudflare Turnstile, Google reCAPTCHA, hCaptcha | Express checkout buttons & bot challenges mount immediately |
| GDPR Consent Banners | Cookiebot, OneTrust, Complianz, CookieYes (ConsentScripts.php) | Mandatory privacy consent dialogs appear on initial arrival |
| Language Switchers | TranslatePress, WPML, Weglot, GTranslate (ESSENTIAL) | Visitors can switch storefront languages on first tap |
| Preloaders & Entrance Animations | elementor-invisible, data-aos, data-sal, theme page-loaders (EXTENDED_GUARD_PATTERN) | Prevents blank hero sections or stuck loading spinners! |
Ready-to-Use Exclusion Patterns for Custom Themes & Plugins#
When your site uses a bespoke header menu script, an above-the-fold custom slider, or an analytics tag that your marketing team requires to fire on 0-second bounce visits even without scroll/movement, paste the matching fragment (one per line) into Delay JavaScript Exclusions (delay_js_exclusions):
# 1. Keep Google Analytics 4 / GTM firing even on 0-scroll bounce visits (optional)
googletagmanager.com/gtag/js
googletagmanager.com/gtm.js
gtag(
# 2. Keep an above-the-fold custom theme mobile menu or search toggle immediate
/themes/your-theme/assets/js/navigation.js
initMobileDrawer
# 3. Keep an above-the-fold Swiper / Owl / Slick hero carousel immediate if desired
swiper.min.js
elementor-frontend
# 4. Keep a third-party booking or live-pricing calculator immediate
calendly.com/assets/external/widget.jsHow matching works in DelayJsOptimizer.php:
- External
<script src="...">: Matches against the script’ssrcURL (includingdata-kadicache-original-srcif minified!) or itsidattribute (e.g.,custom-nav-js). - Inline
<script>...</script>: Matches any unique substring inside the inline script body (such asgtag(orinitMobileDrawer). Keep inline substrings specific (>= 6characters) so you do not accidentally match unrelated scripts! - HTML Attribute Escape Hatch (
data-kadicache-no-delay): Developers can adddata-kadicache-no-delay(ordata-no-delay-js) to any<script>tag or to a parent<header>/<div>container in PHP templates to exempt all scripts inside that container.
Understanding Keep delaying scripts for shoppers (keep_delaying_for_shoppers)#
By default, once a WooCommerce shopper adds an item to their cart, KadiCache prioritizes full immediate script execution so dynamic mini-cart upsells and shipping estimators run with zero delay. However, if your store loads heavy third-party live-chat, heatmap, and ad-pixel bundles that make browsing additional categories sluggish after adding a product to cart, enable Keep delaying scripts for shoppers inside WP Admin -> KadiCache -> CSS & JavaScript—KadiCache continues holding third-party bloat while keeping cart, gallery, and checkout routes protected!
Auditing Third-Party Tag Managers (GTM) Alongside Delay JavaScript#
On marketing-heavy stores, Google Tag Manager (gtm.js) frequently acts as a Trojan horse loading 12 old marketing pixels (LinkedIn Insight, Pinterest Tag, Hotjar, Clarity, Reddit Pixel, Criteo) from campaigns that ended last year:
- Keep GTM Delayed for Maximum
INP&TBTGains: Leavinggtm.jsdelayed until first scroll/tap eliminates400 ms – 1,100 msof mobile CPU blocking on initial arrival while still firing tags as soon as engaged shoppers scroll or tap. - Prune Retired Container Tags Quarterly: Even delayed scripts consume mobile CPU after the user interacts! Removing retired tags inside GTM keeps post-interaction scrolling and swatch taps crisp (
p75 INP <= 200 msin Cookieless RUM). - Server-Side Conversion APIs (
CAPI): Pairing WooCommerce server-side order webhooks with delayed client pixels gives you 100% accurate revenue attribution and99+mobile PageSpeed simultaneously.
Frequently Asked Operational Questions
Will Delay Until Interaction drop my Google Analytics traffic counts?
Why did my mobile hamburger menu need two taps on a custom-coded theme?
Does Delay JavaScript run on /checkout/ or /cart/?
How do I exclude an inline <script> tag that has no src attribute?
What if jQuery itself is needed immediately by an excluded inline script?
Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.