Cloudflare APO WordPress Setup & Rocket Loader Fix
Configure Cloudflare APO WordPress edge caching safely, sync purge queues, and see why Rocket Loader hurts mobile INP.

- By default, Cloudflare caches static
.css,.js, and.webpfiles at 330+ global PoPs while leaving WordPress HTMLcf-cache-status: DYNAMIC—meaning overseas visitors still wait 250–600 ms for transoceanic origin round-trips. - Enabling Cloudflare APO (or KadiCache cookie-aware Cloudflare Edge HTML Cache Rules on Free zones) serves full HTML from the nearest city PoP while bypassing
wordpress_logged_in_*and activewoocommerce_*cart cookies. - Leaving Cloudflare Rocket Loader turned
ONalongside modern WordPressdefer/Delay JSwraps scripts twice, delays hero hydration, and breaks ES modules—KadiCache detects it automatically and turnsrocket_loader = offin 1 click.
Table of Contents (13 sections)
- Why Default Orange-Cloud DNS Leaves WordPress HTML Uncached (DYNAMIC)
- Cloudflare APO vs Modern Cloudflare Cache Rules (CloudflareEdgeRules.php)
- Option A: Cloudflare Automatic Platform Optimization (APO — $5/mo on Free, Included on Pro+)
- Option B: Cookie-Aware Edge HTML Cache Rules (Works on $0 Cloudflare Free Zones!)
- Why You Must Disable Cloudflare Rocket Loader on Optimized WordPress Sites
- Preventing Purge Storms: Queue Merging & Multisite Zone Governance
- 60-Second Verification With curl
- Configuring the 5 Cloudflare Tabs Inside KadiCache Without Breaking SSL or Bots
- 1. SSL/TLS Mode: Why Flexible Triggers Infinite Redirect Loops
- 2. Cloudflare Speed Brain (Speculation Rules) vs WordPress Instant Links
- 3. Cloudflare Fonts vs KadiCache Self-Host Google Fonts (Pick One, Never Both)
- 4. Super Bot Fight Mode & WordPress Loopback / Cron Protection (optimize_wordpress)
- Handling WooCommerce Dynamic Cookies Under Cloudflare APO & Edge Cache Rules
Getting a Cloudflare APO WordPress deployment right separates a globally fast 22 ms edge hit from broken admin bars and frozen mobile menus. When Cloudflare's 330+ edge PoPs and your WordPress origin cache share the same cookie and purge contract, global TTFB drops dramatically. When they conflict, subtle caching bugs multiply.
Why Default Orange-Cloud DNS Leaves WordPress HTML Uncached (DYNAMIC)#
Turn on Cloudflare's orange proxy cloud on a new WordPress domain and run curl -sI https://example.com/. Check the cf-cache-status response header on the main HTML document:
cf-cache-status: DYNAMIC
By default, Cloudflare caches static file extensions (.css, .js, .webp, .woff2, .svg) at the edge, never HTML documents. If your origin server sits in Ashburn, Virginia (us-east-1) with a 4.4 ms KadiCache Early Drop-In hit, a shopper in New York enjoys a 22 ms TTFB—while a shopper in Sydney, Singapore, or Frankfurt still pays 180 ms to 340 ms of speed-of-light fiber latency across TLS + HTTP round-trips back to Virginia.
Caching anonymous public HTML at Cloudflare's edge—while keeping KadiCache's Early Page Cache (advanced-cache.php) and Persistent Object Cache (object-cache.php) warm at the origin—creates a resilient two-layer shield:
| Caching Architecture | Visitor in Same Region (us-east) | Visitor Overseas (eu-central / ap-southeast) | Cache-Miss / Regional PoP Eviction | Logged-In / Active Cart Safety |
|---|---|---|---|---|
| Origin Uncached + Default Cloudflare | 380 ms | 640 ms | 640 ms (hits MySQL every time) | Safe (DYNAMIC) |
| KadiCache Early Drop-In Only (No Edge HTML) | 18 ms | 195 ms (transoceanic hop) | 18 ms (X-KadiCache: HIT) | 100% Safe (CookiePolicy.php) |
| Cloudflare Edge HTML Alone (No Origin Cache) | 20 ms | 24 ms | 480 ms (every regional PoP miss boots WP!) | Risky if cookie rules miss plugins |
| KadiCache Origin + Cloudflare APO / Edge Rule | 18 ms | 22 ms (cf-cache-status: HIT) | 25 ms (Cloudflare pulls from KadiCache HIT!) | 100% Coordinated (cookie + purge sync) |
Look at column 4 in that table. Cloudflare operates over 330 independent city PoPs. Without a fast origin page cache behind Cloudflare, every cold PoP miss in Mumbai, Madrid, or São Paulo still boots full PHP + MySQL! Pairing KadiCache at the origin with Cloudflare at the edge keeps both edge hits and regional PoP fills blazingly fast.
Cloudflare APO vs Modern Cloudflare Cache Rules (CloudflareEdgeRules.php)#
When setting up a Cloudflare APO WordPress workflow today, site owners have two official mechanisms—both managed directly inside WP Admin -> KadiCache -> Cloudflare -> Edge Caching & APO (Integrations/Cdn/Cloudflare/CloudflareZoneControl.php):
Option A: Cloudflare Automatic Platform Optimization (APO — $5/mo on Free, Included on Pro+)#
Cloudflare APO runs an edge Worker backed by Workers KV so once a page is warmed in one PoP, sibling PoPs can pull HTML from KV without hitting your origin.
Inside CloudflareZoneControl::updateApo(), KadiCache configures /zones/<zone>/settings/automatic_platform_optimization cleanly without needing Cloudflare's bloated official WordPress plugin:
- Automatic Hostname Synchronization (
syncedHostnames()): Discovers your primary domain, active multilingual domains (WPML/Polylangseparate-domain setups viaLanguageDomains::active()), and verified Multisite subdomains so APO never drops traffic on secondary language hosts.
- Device-Type Cache Alignment (
cache_by_device_type): Look atCloudflareZoneControl::buildAdvisories()(lines 729–737): if you enable KadiCache'sSeparate Mobile Cachewithout enablingAPO Cache by Device Type, KadiCache immediately warns you and pauses shared Edge HTML caching so mobile markup can never leak onto desktop screens!
Option B: Cookie-Aware Edge HTML Cache Rules (Works on $0 Cloudflare Free Zones!)#
What if you run 15 content sites or WooCommerce stores on Cloudflare Free plans and do not want to pay $5/month × 15 for APO? Inside CloudflareEdgeRules.php, KadiCache deploys a modern Cloudflare Rulesets Phase Entrypoint (http_request_cache_settings) rule with one click.
Unlike old deprecated Cloudflare "Page Rules (Cache Everything)"—which notoriously cached /wp-admin/, wp-login.php, preview drafts, and logged-in user toolbars—KadiCache's scoped Edge HTML Rule caches public GET requests only when zero WordPress auth, comment, preview, or WooCommerce cart/session cookies are present.
Why You Must Disable Cloudflare Rocket Loader on Optimized WordPress Sites#
If you remember only one rule from this entire guide, make it this one: turn Cloudflare Rocket Loader OFF whenever your WordPress cache plugin manages JavaScript execution (defer or Delay JS).
Rocket Loader was invented over a decade ago to help legacy synchronous <script> websites that could not modify their own HTML. Here is what Rocket Loader actually does to your HTML at the Cloudflare edge when left ON:
- Rewrites Every Script
typeAttribute Twice: Rocket Loader mutates<script src="..." defer>into<script type="<24-char-hex>-text/javascript" src="...">and injects an external blocking runtime (/cdn-cgi/scripts/.../cloudflare-static/rocket-loader.min.js).
- Collides With Delay JS (
data-kadicache-delay): KadiCache's JavaScript Defer & Delay engine already holds non-critical scripts as inerttype="text/plain"tags until first user interaction and sequencesDOMContentLoadedsafely for jQuery. Wrapping those scripts a second time inside Rocket Loader breaks script execution order, delays interactive menu hydration on first tap (spiking INP past350 ms!), and triggers broken Gutenberg Interactivity / ES module errors.
- Adds Unnecessary Third-Party Main-Thread Overhead: Lighthouse flags
rocket-loader.min.jsitself under Reduce JavaScript execution time and Avoid chaining critical requests.
Look at CloudflareZoneControl.php inside KadiCache Free Core (applyRecommendedPreset() line 422 and buildAdvisories() line 699):
// Verified preset from KadiCache\Integrations\Cdn\Cloudflare\CloudflareZoneControl::applyRecommendedPreset()
$desired = [
'rocket_loader' => 'off',
'brotli' => 'on',
'early_hints' => 'on',
'http3' => 'on',
'0rtt' => 'on',
'browser_cache_ttl' => 0, // Respect Existing Origin Cache-Control Headers!
'always_online' => 'on',
'security_level' => 'medium',
'tls_1_3' => 'zrt',
];Notice two other critical gems in $desired above:
browser_cache_ttl => 0(Respect Existing Headers): If you set Cloudflare's Browser Cache TTL dropdown to4 hoursor8 daysinstead ofRespect Existing Headers, Cloudflare overwrites your origin'sCache-Controlheaders—either forcing browsers to cache dynamic HTML locally (so logged-in edits never show up!) or shortening KadiCache's1-year(31536000s) immutable static asset TTL! Setting0tells Cloudflare to honor KadiCache's exact per-mime-type headers.
early_hints => 'on'(HTTP 103 Early Hints) +tiered_caching => 'on': Cloudflare sends103 Early Hintsfor preloaded WOFF2 fonts and hero LCP images while fetching from upper-tier regional PoPs (Argo Smart Tiered Caching), cutting cold-PoP origin hits by 60%–80%.
Preventing Purge Storms: Queue Merging & Multisite Zone Governance#
Cloudflare enforces strict API rate limits (1,200 API calls per 5 minutes, and URL purge batch limits). Naive WordPress plugins fire a synchronous POST /zones/<id>/purge_cache HTTP call inside the editor's save_post request—making Gutenberg's "Update" button spin for 3 seconds and dropping purges when WooCommerce updates 80 product stock rows during an import.
KadiCache solves both operational hazards inside CloudflareQueueMerger.php and CloudflareZoneControl::zoneMutationAllowed():
- Coalesced Asynchronous Purge Batches: Rapid post/product edits coalesce into deduplicated URL batches dispatched out-of-band without blocking the editor.
- Multisite Shared-Zone Lock (
multisite_shared_zone_locked): On WordPress Multisite networks where subsite admins share a parent Cloudflare zone (sub1.agency.com,sub2.agency.com), KadiCache prevents a subsite admin from toggling zone-wide SSL or Development Mode settings unless their site runs on a verified standalone custom domain!
60-Second Verification With curl#
After clicking Apply Recommended WordPress Preset inside WP Admin -> KadiCache -> Cloudflare (see our Cloudflare setup doc), run two curl requests from your terminal:
# 1. Verify Edge HTML HIT + Origin Early HIT + Zero Rocket Loader injection
curl -sI https://example.com/ | grep -iE "cf-cache-status|cf-apo-via|x-kadicache|cache-control"
# 2. Confirm rocket-loader.min.js is completely absent from HTML
curl -s https://example.com/ | grep -c "rocket-loader"
# Expected output: 0Finally, verify cookie bypass safety in one command:
# 3. Simulate a logged-in admin cookie — Cloudflare MUST return BYPASS / DYNAMIC!
curl -sI -H "Cookie: wordpress_logged_in_test=1" https://example.com/ | grep -iE "cf-cache-status|x-kadicache"When anonymous requests return cf-cache-status: HIT, logged-in cookie requests return DYNAMIC / BYPASS, and rocket-loader count equals 0, your Cloudflare + WordPress edge stack is production-grade.
Configuring the 5 Cloudflare Tabs Inside KadiCache Without Breaking SSL or Bots#
Beyond APO and Rocket Loader, four adjacent Cloudflare zone settings routinely make or break WordPress stability. Inside WP Admin -> KadiCache -> Cloudflare (CloudflareZoneControl.php), KadiCache organizes every zone API control into five clear sub-tabs (Overview & Purge, Edge Caching & APO, Speed & Network, Security & AI Bots, and SSL/TLS & Connection) so you never hunt through twelve Cloudflare dashboard menus.
1. SSL/TLS Mode: Why Flexible Triggers Infinite Redirect Loops#
When migrating DNS to Cloudflare, leaving SSL/TLS on Flexible causes Cloudflare to connect to visitors over HTTPS (:443) while forwarding requests to your WordPress origin over plain HTTP (:80). WordPress sees $_SERVER['HTTPS'] off, redirects to https://example.com/, Cloudflare intercepts it again over HTTP, and the browser crashes with ERR_TOO_MANY_REDIRECTS!
Look at CloudflareZoneControl::buildAdvisories() (lines 714–721): KadiCache detects ssl === 'flexible' on HTTPS WordPress origins automatically and warns you to switch to Full (Strict) (strict) paired with TLS 1.3 + 0-RTT (zrt) and Always Use HTTPS. With Full (Strict) + HTTP/3 QUIC + 0-RTT Connection Resumption enabled, repeat mobile visitors skip an entire TLS round-trip before requesting cached HTML.
2. Cloudflare Speed Brain (Speculation Rules) vs WordPress Instant Links#
Cloudflare recently rolled out Speed Brain, which injects edge-level Speculation Rules (prefetch headers) to warm likely next navigations. How does that interact with KadiCache's Smart Preload & Instant Links (Optimization/InstantLinks.php)?
- Conservative Edge Prefetch + WooCommerce Exclusions: Speed Brain only prefetches cacheable responses (
cf-cache-status: HIT), while KadiCache'sInstantLinks.phpexplicitly excludes/cart/,/checkout/,/my-account/,?add-to-cart=,wp-login.php, and logout nonce URLs (href_matches/notselectors) so hovering over a "Remove item" or "Log out" button never triggers accidental state mutations!
3. Cloudflare Fonts vs KadiCache Self-Host Google Fonts (Pick One, Never Both)#
Cloudflare's edge Google Fonts rewrite (settings/fonts) proxies fonts.googleapis.com stylesheets through /cf-fonts/... on your domain. Meanwhile, KadiCache's Font Optimization engine (Optimization/FontOptimizer.php) downloads WOFF2 files locally, injects preload hints, and computes fallback @font-face metric overrides (size-adjust, ascent-override).
Enabling both simultaneously is redundant—if KadiCache has already rewritten fonts.googleapis.com to /wp-content/cache/kadicache/fonts/..., Cloudflare Fonts has nothing left to proxy, or worse, runs an unnecessary HTML streaming pass. CloudflareZoneControl::buildAdvisories() flags this overlap (id = 'cloudflare_fonts') so you keep KadiCache's local WOFF2 + Zero-CLS fallback pipeline as the single source of truth.
4. Super Bot Fight Mode & WordPress Loopback / Cron Protection (optimize_wordpress)#
Have you ever turned on Cloudflare Bot Fight Mode and suddenly noticed WP-Cron, REST API health checks, Stripe webhooks, or cache preloading failing with 403 Managed Challenge? That happens when Cloudflare challenges your server's own outbound IP address during loopback requests!
| Cloudflare Setting | Recommended State for WordPress | Why It Matters in Production |
|---|---|---|
| Rocket Loader | OFF | Prevents double script wrapping, ES module errors, and delayed first-tap INP |
| Browser Cache TTL | Respect Existing Headers (0) | Preserves origin no-cache on dynamic HTML and 1-year immutable TTL on static assets |
| SSL / TLS Mode | Full (Strict) + TLS 1.3 (0-RTT) | Eliminates Flexible redirect loops and accelerates mobile QUIC handshakes |
| HTTP/3 (QUIC) + Brotli + Early Hints | ON | Delivers 103 Early Hints for hero LCP images and compresses HTML/CSS 15%–22% tighter than Gzip |
| Optimize for WordPress (Super Bot Fight) | ON (when Bot Fight active) | Prevents Cloudflare from blocking legitimate WordPress cron/loopback and REST webhooks |
Tiered Caching (Argo Tiered) | ON (Free on all plans!) | Concentrates cache misses through upper-tier PoPs so your origin sees 70% fewer fills |
Handling WooCommerce Dynamic Cookies Under Cloudflare APO & Edge Cache Rules#
One final question comes up on every WooCommerce store: "What happens when a customer adds an item to their cart while Cloudflare APO or Edge HTML Cache is enabled?"
Both Cloudflare APO and KadiCache's CloudflareEdgeRules inspect incoming Cookie headers at the edge PoP before serving cached HTML:
- Anonymous Empty-Cart Shopper (90% of traffic): Carries zero
woocommerce_items_in_cart,wp_woocommerce_session_*, orwordpress_logged_in_*cookies -> served straight from the nearest Cloudflare city PoP (cf-cache-status: HIT) in 18–30 ms worldwide! - Active Cart Shopper or Logged-In Customer: Carries
woocommerce_items_in_cart=1orwordpress_logged_in_*-> Cloudflare automatically bypasses shared edge HTML (cf-cache-status: BYPASS/DYNAMIC) and routes to your origin, where KadiCache's Persistent Object Cache accelerates the personalized response.
Frequently Asked Engineering Questions
Do I need the paid $5/month Cloudflare APO add-on, or can I cache WordPress HTML on a Free Cloudflare plan?
Why does Cloudflare Rocket Loader hurt Lighthouse LCP and mobile INP on modern WordPress sites?
What happens if I enable Separate Mobile Cache in WordPress while Cloudflare Edge HTML caching is active?
Does KadiCache require my Global Cloudflare API Key to manage APO and Purge?
Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.
Manage Cloudflare APO, Edge HTML Rules, Early Hints, Tiered Cache, and Varnish from WP Admin.
Step-by-step setup for OAuth PKCE, Scoped API Tokens, SSL Strict, and Rocket Loader.
How origin Early Delivery + Cloudflare Edge PoPs collapse global TTFB below 35 ms.
Set browser_cache_ttl = Respect Existing Headers so origin immutable rules win.