Skip to content

WordPress CDN setup: Cloudflare APO, BunnyCDN, KeyCDN patterns

WordPress CDN configuration patterns for Cloudflare APO, BunnyCDN Perma-Cache, and KeyCDN — what each architecture does, which workloads each fits, and the integration points that matter on a WordPress origin.

A WordPress team chooses a CDN, configures it in twenty minutes, and considers the work done. Three months later, the cache hit ratio is 40%, the origin still serves most of the traffic, and the CDN bill is what it was projected to be despite the underwhelming performance. The configuration patterns below are what differentiate a CDN that actually offloads work from one that just sits in front of the origin and bills for the privilege.

What’s happening

The three CDN architectures have different defaults and require different integration depths with WordPress:

  • Cloudflare APO: full-page HTML cached in Workers KV at the edge, with WordPress-aware purge via the Cloudflare plugin. Caches anonymous traffic aggressively. Requires per-cookie and per-query-param tuning to avoid cache fragmentation.
  • BunnyCDN Perma-Cache: pull-through CDN with optional persistent edge storage. By default a standard CDN for static assets; Perma-Cache adds full HTML caching with explicit edge purge rules. Works well as a Cloudflare alternative when you want simpler pricing.
  • KeyCDN: pull-through CDN focused on static assets. Excellent for images, CSS, JS, and downloads. Lighter integration than the other two — does not natively do full-page HTML caching for WordPress.

How to verify

Identify what the CDN is actually doing:

curl -sI https://www.example.com/ | grep -iE 'cf-cache-status|x-cache|cdn-pullzone|x-keycdn'
curl -sI https://www.example.com/wp-content/uploads/logo.png | grep -iE 'cf-cache-status|x-cache|cdn-pullzone'

A healthy configuration shows cf-cache-status: HIT (Cloudflare) or x-cache: HIT (BunnyCDN, KeyCDN) on both the HTML request and the static asset. A 50% HIT ratio on static assets is acceptable for low-traffic sites; on the HTML request it is a sign of cache fragmentation.

Measure the hit ratio over time via the CDN’s dashboard. Anything below 80% for static assets on a stable site indicates a misconfigured cache rule.

The fix

  1. Pick architecture by workload:

    • High-traffic content site, mostly anonymous: Cloudflare APO.
    • WooCommerce or membership: BunnyCDN Perma-Cache with explicit cookie bypass, or Cloudflare APO with cookie tuning.
    • Static-heavy site (downloads, media): KeyCDN for assets, with a separate page cache at the origin.
    • Compliance constraint requires specific country edge locations: BunnyCDN.
  2. Set up the WordPress side correctly:

    • Cloudflare APO: install the Cloudflare plugin, configure the API token, enable APO on the zone, then add the cookie and query-param tuning under Cache Rules.
    • BunnyCDN: install the BunnyCDN plugin or configure CDN URL rewriting via WP Rocket. Add purge hooks for save_post and comment_post.
    • KeyCDN: configure CDN URL via the CDN Enabler plugin. Add the CDN domain to the WordPress site’s CSP header allowlist.
  3. Configure real client IP forwarding: every CDN puts itself in the TCP path. Without the appropriate X-Forwarded-For or vendor-specific header (CF-Connecting-IP, X-Pull, X-Forwarded-For), WordPress sees every request as coming from a single CDN edge IP. Fix this at the web server level (Nginx real_ip_header, Apache mod_remoteip).

  4. Cache invalidation that covers more than the edited URL: when a post is published, purge the URL, the home page, the category archive, the author archive, the sitemap, and the RSS feed. WordPress CDN plugins typically purge only the URL by default.

  5. Tune cache TTLs explicitly: leave WordPress’s default Cache-Control and you will get inconsistent behavior. Set:

    • Static assets (CSS, JS, images): Cache-Control: public, max-age=31536000, immutable
    • HTML (anonymous): Cache-Control: public, max-age=600, s-maxage=3600
    • HTML (logged-in): Cache-Control: private, no-cache, no-store, max-age=0
  6. Re-measure hit ratio after 48 hours: a correctly configured CDN should show >90% HIT on static assets and >85% HIT on cacheable HTML.

Stack Harbor configures and tunes CDN for WordPress workloads as part of managed enterprise WordPress hosting, including the per-vendor tuning above. If you are paying for a CDN but your origin is still doing the work, book a CDN audit.