Skip to main content
KadiCache
Browse 37 Docs Guides & Search

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.

Optimization/DelayJsOptimizer.phpOptimization/Scripts/DelayScriptClassifier.phpOptimization/ConsentScripts.phpDiagnostics/ScriptConflictAdvice.php
WP Admin -> KadiCache -> CSS & JavaScript -> Delay JavaScript Exclusions
MODULE 16 · 2X RETINA
Granular script URL, ID, inline snippet, and page-path exclusions bypass interaction delay whenever immediate execution is required.2880×1840 WebP
Quick Summary · 30-Second Operational SpecSource-Verified Guide
WP Admin Path
WP Admin -> KadiCache -> CSS & JavaScript (Delay JS)
Expected Outcome
Near-0 ms Mobile TBT · Built-In WooCommerce & GDPR Guards
Key Marker / Engine
DelayJsOptimizer.php | data-kadicache-no-delay
  • 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-delay attribute, and page-path exclusions plus Keep 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.

FIG 01Entering script filenames, external domains, inline keywords, and excluded routes inside WP Admin -> KadiCache -> CSS & JavaScriptZoom 2x

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 CategoryBuilt-In Handles & Domains Guarded AutomaticallyWhy It Stays Immediate
WooCommerce Product Gallerieswc-single-product, zoom, flexslider, photoswipe, photoswipe-ui-defaultShoppers can swipe photos & tap variation swatches on first touch
Cart & 6 Wishlist PluginsWooCommerce mini-cart fragments + WPC, YITH, TI, WCBoost, QODE & MoreConvert wishlistsHeader cart & wishlist badge counts stay accurate without waking all JS
Payments & Anti-Bot SDKsStripe, PayPal, Cloudflare Turnstile, Google reCAPTCHA, hCaptchaExpress checkout buttons & bot challenges mount immediately
GDPR Consent BannersCookiebot, OneTrust, Complianz, CookieYes (ConsentScripts.php)Mandatory privacy consent dialogs appear on initial arrival
Language SwitchersTranslatePress, WPML, Weglot, GTranslate (ESSENTIAL)Visitors can switch storefront languages on first tap
Preloaders & Entrance Animationselementor-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):

TEXTCopy-Paste Reference Patterns for Delay JavaScript 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.js

How matching works in DelayJsOptimizer.php:

  • External <script src="...">: Matches against the script’s src URL (including data-kadicache-original-src if minified!) or its id attribute (e.g., custom-nav-js).
  • Inline <script>...</script>: Matches any unique substring inside the inline script body (such as gtag( or initMobileDrawer). Keep inline substrings specific (>= 6 characters) so you do not accidentally match unrelated scripts!
  • HTML Attribute Escape Hatch (data-kadicache-no-delay): Developers can add data-kadicache-no-delay (or data-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 & TBT Gains: Leaving gtm.js delayed until first scroll/tap eliminates 400 ms – 1,100 ms of 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 ms in Cookieless RUM).
  • Server-Side Conversion APIs (CAPI): Pairing WooCommerce server-side order webhooks with delayed client pixels gives you 100% accurate revenue attribution and 99+ mobile PageSpeed simultaneously.

Frequently Asked Operational Questions

Will Delay Until Interaction drop my Google Analytics traffic counts?
Over 92%+ of engaged human visitors scroll, tap, or move the cursor within 1 second of page paint, firing analytics normally. If your marketing team strictly tracks 0-second bounce sessions where a user closes the tab without scrolling or moving the mouse, either enable Delay JS fallback timeout mode or add googletagmanager.com / gtag( to Delay JavaScript Exclusions.
Why did my mobile hamburger menu need two taps on a custom-coded theme?
Some custom theme scripts attach menu listeners lazily without handling replayed pointer events. Adding just that tiny 4 KB navigation script filename (e.g. menu.js) to Delay JavaScript Exclusions makes the menu open on the very first tap while still delaying 800 KB+ of GTM, pixels, and chat widgets!
Does Delay JavaScript run on /checkout/ or /cart/?
Never. DelayJsOptimizer.php automatically bypasses WooCommerce Cart, Checkout, and My Account pages so payment gateways and checkout validation always run immediately.
How do I exclude an inline <script> tag that has no src attribute?
Copy a unique function name, object property, or variable identifier from inside that inline <script> block (for example window.MyCustomWidgetConfig) and paste it on its own line in Delay JavaScript Exclusions—or add data-kadicache-no-delay directly to the <script> tag.
What if jQuery itself is needed immediately by an excluded inline script?
DelayJsOptimizer and DelayScriptClassifier analyze dependency relationships automatically: whenever an active/excluded script requires jQuery, jquery-core is kept active alongside it so ReferenceErrors do not occur.
Gergis — Lead Systems & Cache Architect
Principal WordPress & Cloud Edge Architect
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/Scripts/DelayScriptClassifier.phpapps/wordpress-plugin/src/Optimization/ConsentScripts.phpapps/wordpress-plugin/src/Diagnostics/ScriptConflictAdvice.php
Was this engineering guide helpful?