- Separates non-blocking
Defer JavaScriptfromDelay Until Interactionso site owners can choose conservative compatibility or maximum main-thread relief. - Automatically protects parser-dependent inline scripts, Content-Security-Policy nonces/hashes (
CspPolicy.php), GDPR consent banners (ConsentScripts.php), payment SDKs, and multilingual switchers. - Guards WooCommerce single-product galleries (
wc-single-product,zoom,flexslider,photoswipe), mini-cart fragments, and 6 popular wishlist counter plugins. - Provides independent
Delay,Defer, andMinifyexclusion drawers plusKeep delaying scripts for shoppersfor stores with active carts.
Table of Contents (5 sections)
- Why Third-Party & Theme JavaScript Dominates Mobile Main-Thread Blocking
- Choosing the Right Execution Mode: Off vs Defer vs Delay Until Interaction
- Built-In Safeguards Inside DelayJsOptimizer.php & DelayScriptClassifier.php
- Configuring Minify, Defer & Delay Exclusions in WP Admin -> KadiCache
- Step-by-Step Verification & Troubleshooting Workflow
Why Third-Party & Theme JavaScript Dominates Mobile Main-Thread Blocking#
Even after Early PHP Drop-In Page Caching cuts server Time to First Byte (TTFB) below 20 milliseconds, modern WordPress and WooCommerce pages routinely stall on mid-range mobile phones for 1.5 to 4.0 seconds. The culprit is synchronous and early main-thread JavaScript evaluation. A typical commercial storefront loads jQuery core, theme navigation bundles, Elementor frontend handlers, Swiper carousels, Google Tag Manager, Meta Pixel, TikTok analytics, live chat widgets, review badges, and customer heatmaps—often totaling 650 KB to 1.8 MB of compressed JavaScript (2.5 MB+ uncompressed) during initial page load.
On mobile CPUs, downloading scripts is only the beginning. Every <script> without defer or async pauses the HTML parser, forces V8 or JavaScriptCore to parse and compile bytecode on the main UI thread, and triggers long tasks (> 50 ms) that inflate Lighthouse Total Blocking Time (TBT) and degrade real-visitor Interaction to Next Paint (INP). If a visitor taps a mobile menu icon or product size swatch while a 280 ms third-party analytics bundle is executing, the browser cannot paint the visual response until that task finishes.
Naive "delay all JavaScript" plugins attempt to fix TBT by blindly rewriting every <script> tag on the page to a fake MIME type until the user moves a mouse or touches the screen. In production WordPress environments, blind script delaying causes four immediate regressions:
- Blank Hero Sections & Frozen Preloaders: Themes with CSS entrance animations (
elementor-invisible,data-aos,data-sal) or full-screen page-loader overlays stay invisible until the visitor taps an apparently blank white screen. - Broken WooCommerce Product Galleries & Express Checkout: Single-product image zoom, FlexSlider thumbnails, PhotoSwipe lightboxes, Stripe Payment Elements, PayPal buttons, and Cloudflare Turnstile challenges fail to render above the fold.
- Compliance & Consent Violations: Delaying Cookiebot, OneTrust, Complianz, or CookieYes prevents mandatory GDPR/ePrivacy consent banners from appearing on initial arrival.
- Strict Content-Security-Policy (
CSP) Failures: Injecting inline bootstrapper scripts onto sites running hash-based or nonce-lessscript-srcheaders triggers browser CSP violations that block script execution completely.
KadiCache eliminates those trade-offs in Free Core through ScriptOptimizer.php, DelayJsOptimizer.php, and DelayScriptClassifier.php—combining clean HTML5 defer orchestration with a context-aware Delay Until Interaction engine.
Choosing the Right Execution Mode: Off vs Defer vs Delay Until Interaction#
Inside WP Admin -> KadiCache -> CSS & JavaScript (and Step 2 of the guided Setup Wizard), KadiCache presents clear execution modes rather than forcing every site into aggressive script rewriting:
| JavaScript Strategy | How Scripts Load & Run | Ideal WordPress Use Case | Typical Mobile TBT & INP Impact |
|---|---|---|---|
| Off (Original Order) | Leaves script tags untouched (Minify JS can still compress local assets) | Legacy custom web apps relying on synchronous document.write() | Baseline (400 – 1,400 ms TBT) |
| Defer Non-Critical JS | Adds defer while preserving exact DOM execution order across dependent chains | Content portals, membership sites, and complex interactive calculators | Cuts parser blocking (90 – 240 ms TBT) |
| Delay Until Interaction | Holds non-essential theme & third-party scripts in inert type="text/plain" state until first user action (or optional fallback timer) | WooCommerce stores, marketing landing pages, Elementor/Divi sites, ad-heavy blogs | Near-zero initial TBT (0 – 40 ms · < 100 ms INP) |
When Defer Non-Critical JavaScript is active, ScriptOptimizer.php inspects the full dependency chain before adding defer. Any script that calls document.write() (ParserDependentScripts.php) or inline initialization block that depends on an un-deferred synchronous parent is kept in safe order so jQuery is not defined errors do not occur.
When Delay Until Interaction is active (DelayJsOptimizer.php, guarded by a MAX_HTML = 2,097,152 byte document safety ceiling), KadiCache classifies every script on the page before deciding whether to keep it live on initial paint or hold it until the visitor scrolls, taps, clicks, presses a key, or moves the pointer.
Built-In Safeguards Inside DelayJsOptimizer.php & DelayScriptClassifier.php#
Rather than forcing site owners to hunt down dozens of obscure script handles manually, KadiCache ships deterministic compatibility classifiers verified across popular WordPress ecosystems:
- WooCommerce Gallery & Shopper Continuity: On single WooCommerce product templates, KadiCache automatically protects
GALLERY_HANDLES(wc-single-product,zoom,flexslider,photoswipe,photoswipe-ui-default) so product photography, variation gallery swaps, and zoom lenses respond on first tap. Meanwhile, mini-cart counters and 6 supported wishlist plugins refresh cleanly without prematurely waking heavy marketing tags. By default, when a shopper has items in their cart, KadiCache relaxes script delaying for maximum checkout responsiveness—or you can toggle Keep delaying scripts for shoppers (keep_delaying_for_shoppers) when third-party chat/analytics tags still weigh down active shopping sessions. - Payment Gateways, Bot Challenges & Consent Managers:
INDEPENDENT_SDKSandConsentScripts.phpautomatically recognize Stripe, PayPal, Cloudflare Turnstile, Google reCAPTCHA, hCaptcha, Cookiebot, OneTrust, Complianz, and CookieYes so checkout security challenges and privacy consent banners appear immediately without user interaction. - Multilingual Switchers (
ESSENTIAL): Client-side and hybrid language switchers from TranslatePress, WPML, Weglot, and GTranslate stay responsive immediately on arrival. - Entrance Animations & Preloader Guards (
EXTENDED_GUARD_PATTERN): Pages containing theme preloaders or scroll-triggered visibility classes (elementor-invisible,data-aos,data-sal) receive automatic protection so above-the-fold headlines and hero cards never remain stuck atopacity: 0. - CSP Header Inspection (
CspPolicy.php): Before injecting its lightweight interaction listener, KadiCache inspects activeContent-Security-Policyheaders. If strictscript-srcrules forbid inline bootstrap execution without a dynamic nonce, KadiCache gracefully abstains rather than breaking page interactivity.
Configuring Minify, Defer & Delay Exclusions in WP Admin -> KadiCache#
Every JavaScript control inside WP Admin -> KadiCache -> CSS & JavaScript is isolated so you can tune individual scripts or landing pages in seconds without turning off sitewide optimization:
- Minify JavaScript Files (
minify_js_enabled): Strips comments and whitespace from local JavaScript files while automatically skipping pre-minified*.min.jsbundles so CPU cycles are never wasted re-compressing vendor libraries. - Delay Execution Trigger Mode (
delay_js_mode): Choose strict interaction-only holding for the highest Lighthouse performance score, or enable a gentle fallback timeout when passive wallboard or analytics sessions must fire even if a visitor reads without scrolling. - Delay JavaScript Exclusions (
delay_js_exclusions): Enter one rule per line matching a script filename (custom-slider.js), WordPress script ID (#my-calculator-js), external domain (challenges.cloudflare.com), or unique inline variable name (initCustomHeader). Matched scripts execute normally while all remaining third-party tags stay delayed. - Excluded JavaScript Page Paths (
delay_js_excluded_paths): Bypass Delay JS on specific routes such as/custom-configurator/*or/mortgage-calculator/while keeping Page Caching, Cloud Remove Unused CSS, and Media Lazyload active. Individual posts and pages can also toggle Delay JS off directly from the Gutenberg Block Editor sidebar or the Frontend Admin Bar.
Step-by-Step Verification & Troubleshooting Workflow#
After enabling Defer or Delay Until Interaction, run this 60-second verification checklist before closing WP Admin:
- Test Logged-Out Incognito Arrival (Hands Off Mouse/Trackpad): Open your homepage, a category archive, and a single WooCommerce product page in a fresh Incognito window without moving the cursor. Confirm the header logo, navigation bar, hero headline, and product gallery look complete before any interaction.
- Verify First-Tap Responsiveness: Tap the mobile hamburger menu, open the search drawer, switch product variations, and open the mini-cart. Delayed UI handlers prioritize interactive readiness ahead of low-priority marketing beacons.
- Compare Cached vs Uncached in PageSpeed Lab: Open
WP Admin -> KadiCache -> Core Web Vitals -> PageSpeed & CrUX Lab(Built-In RUM & PageSpeed Insights) and run Compare Cached vs Uncached on Mobile to verifyTotal Blocking Time (TBT)drops toward0 msand third-party bootup warnings disappear. - Isolate Any Custom Theme Script in 10 Seconds: If a bespoke theme widget needs immediate execution on page load, paste its filename fragment into Delay JavaScript Exclusions, click Save & Purge, and re-test—keeping 95% of your third-party tag weight off the main thread. For full rule syntax, read our Delay JS & Exclusions Guide and explore all Lighthouse remedies in the PageSpeed Audits Hub.
Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.