Skip to main content
KadiCache
Commerce & Pulse MCPFree Core

Cloudflare OAuth, CDN & Varnish Bridge

Synchronizes local purges cleanly with Cloudflare (batched 30-URL parallel purges + 429 Retry-After queue), Varnish VCL 4.1, host caches (Kinsta, Cloudways, SiteGround, Breeze), and optional pull-CDN URL rewriting.

Targeted Edge Sync
18 ms
Verified Source Entry
apps/wordpress-plugin/src/Integrations/Cdn/Cloudflare/CloudflareOAuth.php
Verified Engine Capabilities

Engineered for zero regressions.

  • 1-Click Cloudflare OAuth + zone-scoped API token support with automatic 429 Retry-After backoff
  • Batched 30-URL parallel Cloudflare purges with Action Scheduler overflow queue
  • Varnish VCL 4.1 targeted PURGE with Multisite shared-host safety guards
  • Verified Static Pull-CDN URL rewriting with automated font CORS check
Synchronized Origin, Cloudflare & Varnish Purge via WP-CLI
$ wp kadicache status --format=json
$ wp kadicache purge https://example.com/pricing/
$ wp kadicache purge --all
# Atomically purges local FileCache, dispatches Cloudflare URL/Zone purge,
# and triggers queued Varnish PURGE/BAN invalidation with automatic retry
Inside the KadiCache WordPress Plugin

Cloudflare OAuth, CDN & Varnish Bridge — Plugin Interface

5 live 2x Retina plugin screens
WP Admin -> KadiCache -> Cloudflare -> Overview & Purge
MODULE 13 · 2X RETINA
Live Cloudflare GraphQL Edge Analytics, Quick Development Mode, and targeted URL/zone purge controls.2880×1840 WebP
100% Source-Code Verified9 min engineering readUpdated 2026-11-23
Executive Summary · 30-Second SpecZero-Regressions Spec
WP Admin Path
WP Admin -> KadiCache -> Cloudflare + CDN
Measured Impact
5-Tab Cloudflare Center · Zero-Knowledge PKCE · CORS-Safe CDN
Verification Marker
cf-edge-cache: cache,platform=wordpress | Access-Control-Allow-Origin
  • Connects Cloudflare in 1 click via Zero-Knowledge OAuth 2.0 + PKCE (S256) where code_verifier stays encrypted inside SecretBox, 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"> and crossorigin="use-credentials" to prevent CORS breakages.
  • Synchronizes reverse-proxy invalidations with Varnish (VarnishPurge.php) using Action Scheduler retries and automatic coexistence with Proxy Cache Purge and Cloudways Breeze.
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:

  1. 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!).
  2. 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.
  3. Broken Webfonts & ES Modules on Pull-Zone CDNs: Naive regex CDN rewriters blindly swap the hostname on <script type="module"> imports and WOFF2 fonts without Access-Control-Allow-Origin headers, 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):

  1. 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.php so burst post edits never hit Cloudflare API rate limits.
  2. Edge Caching & APO: Coordinates Cloudflare Automatic Platform Optimization (APO) and Free Edge Cache Rules directly with CachedResponse::serve(). Eligible public guest HIT responses emit cf-edge-cache: cache,platform=wordpress, Cache-Control: public, max-age=0, s-maxage=... (automatically capped to 14,400s when nonce_ttl_cap applies!), and site-scoped Cache-Tag headers—while private, cart, or uncached responses explicitly emit cf-edge-cache: no-cache.
  3. 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.
  4. Security & AI Bots: Configures AI Bot Blockers, Bot Fight Mode, Browser Integrity Check, and Zone Security Level right inside WordPress.
  5. SSL/TLS & Connection: Verifies Full (Strict) encryption mode (preventing infinite redirect loops caused by Cloudflare Flexible SSL!), Always Use HTTPS, Minimum TLS Version, and self-managed Agency OAuth client overrides (KADICACHE_CLOUDFLARE_OAUTH_CLIENT_ID).
Edge LayerTypical Standalone SetupKadiCache Coordinated Edge Pipeline
Credential SecurityRaw Global API Key stored in plaintext wp_optionsOAuth 2.0 PKCE (S256) + SecretBox encryption at rest
Guest Nonce Pages on APOCached at Edge for 30 days -> broken formsAuto-capped s-maxage <= 14400s when nonce_ttl_cap is present
Rocket Loader + Delay JSDouble script rewrite -> broken checkout UILive conflict detection & 1-click Rocket Loader disable
Burst WooCommerce EditsSynchronous API calls stalling post.php saveBatched 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:

FIG 01Per-asset-type toggles and 1-click Nginx / Apache Access-Control-Allow-Origin snippetsZoom 2x
  • Per-Asset Granularity: Independently toggle cdn_images, cdn_css, cdn_js, cdn_fonts, and cdn_media across src, srcset, imagesrcset, poster, data-src, data-bg, and delayed data-kadicache-delay scripts.
  • ES Module & Credentialed CORS Immunity: CdnUrlRewriter::attributes() intentionally keeps <script type="module">, <link rel="modulepreload">, <a download>, and elements with crossorigin="use-credentials" on your origin domain so relative ES module import bases and credentialed CORS requests never break—and verifies CspPolicy before 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 .htaccess snippets 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 active Proxy Cache Purge (varnish-http-purge) or Cloudways Breeze Varnish listeners so duplicate PURGE floods 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-Proto split purging (varnish_split_proto), regex ban patterns (varnish_query_regex), and trusted proxy IP validation (TrustedProxy.php under Tools -> Proxy, 404 & Hints). Failed network purges automatically queue a bounded second attempt in kadicache_varnish_retry via Action Scheduler.
NGINXNginx Font CORS Header Snippet (Generated in WP Admin -> KadiCache -> CDN)
location ~* \.(?:woff2?|ttf|otf|eot)$ {
    add_header Access-Control-Allow-Origin "*" always;
    expires 365d;
    add_header Cache-Control "public, max-age=31536000, immutable";
}
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/Integrations/Cdn/Cloudflare/CloudflareOAuth.phpapps/wordpress-plugin/src/Integrations/Cdn/Cloudflare/CloudflareEdgeRules.phpapps/wordpress-plugin/src/Integrations/Cdn/CloudflarePurge.phpapps/wordpress-plugin/src/Optimization/CdnUrlRewriter.phpapps/wordpress-plugin/src/Integrations/Proxy/VarnishPurge.php

Technical FAQ

Do I need to give KadiCache my Cloudflare Global API Key?

Never. KadiCache connects via 1-Click Zero-Knowledge OAuth 2.0 + PKCE (S256) or a narrowly scoped API Token pre-filled via CloudflareOAuth::tokenTemplateUrl(), encrypted at rest with SecretBox.

How does KadiCache prevent Cloudflare APO from caching logged-in users or WooCommerce carts?

CachedResponse::serve() emits cf-edge-cache: cache,platform=wordpress and public s-maxage ONLY on verified anonymous HIT responses free of session cookies, renewal cookies, or private nonces, and explicitly sends cf-edge-cache: no-cache on dynamic or personalized requests.

Why did KadiCache flag Cloudflare Rocket Loader in my dashboard?

Cloudflare Rocket Loader rewrites all <script> tags asynchronously at the edge, which conflicts with WordPress Defer and Delay JavaScript engines and frequently breaks WooCommerce checkout scripts. KadiCache detects active Rocket Loader via the Cloudflare API and lets you disable it in one click.

Why does CdnUrlRewriter skip <script type="module"> tags?

Rewriting an ES module entry script to cdn.example.com changes import.meta.url and relative import resolution while triggering strict cross-origin module checks—a common bug in WordPress 6.5+ Interactivity API blocks when naive regex CDN plugins are used.

Can I use both Cloudflare DNS proxy and a separate Pull-Zone CDN like BunnyCDN?

Yes. You can manage zone HTML/security settings and purges in the Cloudflare tab while rewriting static wp-content uploads/assets to a dedicated BunnyCDN or CloudFront CNAME in the CDN tab.

What happens if my local Varnish daemon temporarily rejects a PURGE request?

VarnishPurge::run() records the status in kadicache_varnish_status and schedules a deduplicated background retry via Action Scheduler (kadicache_varnish_retry) without blocking your post editor save.

Does Multisite allow sharing one Cloudflare Zone across all subsites?

Yes. Network Shared Configuration lets Super Admins connect a single network-wide Cloudflare Zone and lock subsite zone mutations (CloudflareZoneControl::zoneMutationAllowed()) while still allowing per-subsite URL purges.