- Connects Cloudflare in 1 click via Zero-Knowledge OAuth 2.0 + PKCE (
S256) wherecode_verifierstays encrypted insideSecretBox, or via a pre-scoped API Token template. - Manages 5 dedicated Cloudflare sub-tabs (
Overview & Purge,Edge Caching & APO,Speed & Network,Security & AI Bots,SSL/TLS) and detects Rocket Loader conflicts automatically. - Rewrites HTML & CSS asset URLs to your Pull-Zone CDN (
CdnUrlRewriter.php) while skipping<script type="module">andcrossorigin="use-credentials"to prevent CORS breakages. - Synchronizes reverse-proxy invalidations with Varnish (
VarnishPurge.php) using Action Scheduler retries and automatic coexistence withProxy Cache Purgeand CloudwaysBreeze.
Table of Contents (4 sections)
Why Origin Caching Alone Cannot Beat Intercontinental Network Physics#
When your origin VPS sits in Frankfurt, a visitor in Frankfurt receives a KadiCache advanced-cache.php Early HIT in 14 ms—but a shopper in Sydney, São Paulo, or Tokyo still pays 180 ms to 320 ms of submarine fiber round-trip latency just to complete TCP + TLS handshakes and fetch the HTML document. Conversely, turning on aggressive CDN or Varnish HTML caching without deep WordPress coordination causes three classic failures:
- Stale Articles & Prices After Edits: Updating a product price purges local WordPress disk cache, while Cloudflare APO or Varnish continues serving yesterday's HTML at the edge for hours—or worse, plugins require pasting your Global Cloudflare API Key (granting full DNS takeover access across every domain in your Cloudflare account!).
- Rocket Loader + Delay JS Collisions: Enabling Cloudflare's legacy Rocket Loader alongside WordPress JavaScript deferral rewrites
<script>tags twice, breaking mobile menus, WooCommerce checkout gateways, and Elementor sliders. - Broken Webfonts & ES Modules on Pull-Zone CDNs: Naive regex CDN rewriters blindly swap the hostname on
<script type="module">imports and WOFF2 fonts withoutAccess-Control-Allow-Originheaders, filling the browser console with CORS errors and blank fallback text.
KadiCache unifies Cloudflare Edge Control, Pull-Zone CDN Rewriting, and Varnish Reverse-Proxy Invalidation into one coordinated invalidation bus—included in Free Core.
Zero-Knowledge Cloudflare OAuth 2.0 (PKCE S256) & 5-Subtab Command Center#
Unlike plugins that ask for your Global API Key + account email, CloudflareOAuth.php implements Zero-Knowledge OAuth 2.0 Authorization Code + PKCE (S256) alongside a 1-click Scoped API Token Builder (CloudflareOAuth::tokenTemplateUrl()):
Once connected, WP Admin -> KadiCache -> Cloudflare unlocks 5 specialized sub-tabs (CloudflareZoneControl.php, CloudflareEdgeRules.php, CloudflareAnalytics.php):
- Overview & Purge: Displays 24-hour GraphQL Edge Analytics (total requests, edge cache ratio, bandwidth saved, mitigated threats), 1-click Development Mode (3-hour bypass with auto-expiry), and instant Zone / URL purge actions merged via
CloudflareQueueMerger.phpso burst post edits never hit Cloudflare API rate limits. - Edge Caching & APO: Coordinates Cloudflare Automatic Platform Optimization (APO) and Free Edge Cache Rules directly with
CachedResponse::serve(). Eligible public guestHITresponses emitcf-edge-cache: cache,platform=wordpress,Cache-Control: public, max-age=0, s-maxage=...(automatically capped to14,400swhennonce_ttl_capapplies!), and site-scopedCache-Tagheaders—while private, cart, or uncached responses explicitly emitcf-edge-cache: no-cache. - Speed & Network: Controls Speed Brain speculative prefetching, 103 Early Hints, HTTP/3 (QUIC), 0-RTT Connection Resumption, Brotli, and Polish/Argo add-ons—plus an automatic Rocket Loader Conflict Guard (
ScriptConflictAdvice.php) that detects and turns off Rocket Loader with one click before it can collide with Defer & Safe Delay JavaScript. - Security & AI Bots: Configures AI Bot Blockers, Bot Fight Mode, Browser Integrity Check, and Zone Security Level right inside WordPress.
- SSL/TLS & Connection: Verifies
Full (Strict)encryption mode (preventing infinite redirect loops caused by CloudflareFlexibleSSL!), Always Use HTTPS, Minimum TLS Version, and self-managed Agency OAuth client overrides (KADICACHE_CLOUDFLARE_OAUTH_CLIENT_ID).
| Edge Layer | Typical Standalone Setup | KadiCache Coordinated Edge Pipeline |
|---|---|---|
| Credential Security | Raw Global API Key stored in plaintext wp_options | OAuth 2.0 PKCE (S256) + SecretBox encryption at rest |
| Guest Nonce Pages on APO | Cached at Edge for 30 days -> broken forms | Auto-capped s-maxage <= 14400s when nonce_ttl_cap is present |
| Rocket Loader + Delay JS | Double script rewrite -> broken checkout UI | Live conflict detection & 1-click Rocket Loader disable |
| Burst WooCommerce Edits | Synchronous API calls stalling post.php save | Batched async queue via CloudflareQueueMerger & Action Scheduler |
Context-Aware Pull-Zone CDN Rewriter (CdnUrlRewriter.php) & Font CORS#
Not every site uses Cloudflare DNS—many agencies pair Kinsta, Cloudways, or AWS origins with BunnyCDN, CloudFront, Fastly, or KeyCDN pull zones (cdn.example.com). Instead of running a fragile global string-replace across raw HTML, CdnUrlRewriter.php parses final 200 OK HTML documents through HookFreeTagProcessor and rewrites url(...) tokens inside <style> blocks and generated stylesheets:
- Per-Asset Granularity: Independently toggle
cdn_images,cdn_css,cdn_js,cdn_fonts, andcdn_mediaacrosssrc,srcset,imagesrcset,poster,data-src,data-bg, and delayeddata-kadicache-delayscripts. - ES Module & Credentialed CORS Immunity:
CdnUrlRewriter::attributes()intentionally keeps<script type="module">,<link rel="modulepreload">,<a download>, and elements withcrossorigin="use-credentials"on your origin domain so relative ES module import bases and credentialed CORS requests never break—and verifiesCspPolicybefore mutating inline style attributes! - Live Font CORS Verification & Server Snippets: Cross-origin WOFF2 fonts fail in Chromium and Firefox unless the origin sends
Access-Control-Allow-Origin. The CDN tab displays live Font CORS status pills and provides copy-ready Nginx and Apache.htaccesssnippets inside the Asset Rules & CORS modal (#kc-cdn-dialog)—working hand-in-hand with Local Google Fonts & Binary Subsetting.
Varnish Reverse-Proxy Bridge & Trusted Proxy Headers#
On Varnish-accelerated stacks (Cloudways, DreamHost, custom Varnish 6/7 VCL, or Plesk/Nginx microcaches), VarnishPurge.php, VarnishDiscovery.php, and VarnishTransportClient.php keep your reverse proxy synchronized with local cache purges:
- Automatic Coexistence (
VarnishPurge::proxyCachePurgeActive()): Detects activeProxy Cache Purge(varnish-http-purge) or CloudwaysBreezeVarnish listeners so duplicatePURGEfloods are avoided while filling gaps on query-string and asset-publication invalidations. - Custom Varnish Target, Protocol Split & Retry Queue: Configure custom loopback/internal Varnish socket addresses (
varnish_address),X-Forwarded-Protosplit purging (varnish_split_proto), regex ban patterns (varnish_query_regex), and trusted proxy IP validation (TrustedProxy.phpunderTools -> Proxy, 404 & Hints). Failed network purges automatically queue a bounded second attempt inkadicache_varnish_retryvia Action Scheduler.
location ~* \.(?:woff2?|ttf|otf|eot)$ {
add_header Access-Control-Allow-Origin "*" always;
expires 365d;
add_header Cache-Control "public, max-age=31536000, immutable";
}Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.