Running WordPress at the Edge: Using Cloudflare Workers to Bypass PHP

WordPress edge caching Cloudflare – Many WordPress sites struggle to deliver “instant” loading for visitors around the world. When a visitor clicks a link, the request travels across the Internet to a single origin server, where PHP and MySQL assemble the page. This round‑trip latency and dynamic processing can add hundreds of milliseconds to Time to First Byte (TTFB). On high‑traffic media sites or global e‑commerce stores the delay is obvious: page loads feel sluggish and core web vitals suffer. Some engineering leaders think the solution is “headless WordPress,” but running an app stack for content that rarely changes is often overkill. Instead, you can run WordPress at the edge.

Why traditional WordPress architecture struggles with speed

WordPress’ default architecture generates each page using PHP templates, database queries and plugins. While caching plugins can store static assets, the HTML output is usually generated by the origin server. If visitors are distributed across continents, every request still travels to your single data centre. This results in slow TTFB. Kinsta notes that modern CDNs can handle some dynamic content, but it requires advanced knowledge and a complex setup. Without proper purge mechanisms, dynamic content can become stale, and edge caching may conflict with certain WordPress settings.

Some hosts integrate basic edge caching, but their caches often exclude HTML or can’t purge pages quickly. Cloudflare’s free CDN caches static assets (images, CSS, JS) yet still forwards most HTML requests to the origin. To truly accelerate WordPress you need to cache HTML at the edge and serve anonymous visitors without hitting PHP.

Enter Cloudflare Workers and Automatic Platform Optimization

Cloudflare Workers are server‑side JavaScript functions that run on Cloudflare’s network of more than 300 points of presence. They start in a few milliseconds and can inspect, modify or respond to requests before they reach your origin. WisdmLabs compares them to nimble little site boosters that zip into action across the globe. When combined with Cloudflare’s Automatic Platform Optimization (APO), Workers deliver dramatic improvements:

  • Edge HTML caching: The worker caches HTML responses on every edge data centre. Cloudflare’s blog explains that the worker uses the Cache API to serve cached HTML when the request meets certain conditions (GET, status 200, text/html content type, no query string and no WordPress cookies). Logged‑in users, preview pages and pages with Cache‑Control: no‑cache headers automatically bypass the cache.

  • Automatic purging: The WordPress plugin adds a cf-edge-cache header to HTML responses. Whenever you update a post or page, the plugin triggers Cloudflare’s API to purge the specific URL from the edge cache. With APO enabled, HTML caches have a default time‑to‑live of 30 days and are invalidated within 30 seconds of content changes.

  • Workers KV for replication: To avoid stale content, Cloudflare uses Workers KV (a distributed key‑value store) to replicate cached HTML across data centres. When a page is updated, a purge event writes new metadata to KV so all edges know there is a fresh version.

This architecture dramatically reduces TTFB. Cloudflare’s “Improving HTML Time to First Byte” post notes that caching HTML at the edge can improve TTFB by over 3 seconds for anonymous visitors. WisdmLabs highlights that edge caching can cut hundreds of milliseconds off load times and raise cache hit rates to 95 %. In one example a travel blogger saw their homepage drop from 2 seconds to 0.5 seconds for visitors in Europe. Faster TTFB improves Largest Contentful Paint (LCP) and helps your site rank better in Google.

Bypassing PHP entirely for anonymous users

When a page is served from the edge, the origin PHP processes are not invoked. This means fewer concurrent PHP workers, lower CPU usage and lower database load. For high‑traffic publishers this can remove the need for extra servers. Cloudflare’s blog emphasises that edge caching bypasses HTML generation entirely for guest users and only fetches from the origin if the page isn’t cached or if the request has cookies indicating a logged‑in session. Because Cloudflare never caches responses containing WordPress cookies, the admin bar and personal dashboards remain dynamic and secure.

When and when not to use edge caching

Edge caching is ideal when:

  • Traffic is global. If your audience spans continents, edge caching delivers a local experience. WisdmLabs suggests enabling edge caching if you get traffic from more than one country or have a content‑heavy site.

  • Pages are mostly static. Blogs, news sites and marketing pages benefit the most. Dynamic elements like comment counts can be handled via JavaScript fetches from the origin.

  • You need to offload origin servers. Serving HTML from the edge frees up your servers to handle API endpoints or complex dynamic actions.

Edge caching may not be appropriate if:

  • Every page is personalised. Dashboards, membership portals or fully dynamic applications rely on user‑specific data. You can still cache static assets via the CDN but not the HTML.

  • You heavily use WooCommerce cart or checkout pages. These pages must bypass caching to avoid showing one user’s cart to another. WisdmLabs recommends excluding cart/checkout pages from caching and testing thoroughly.

  • Traffic is minimal. If you get fewer than 100 visitors a day, the complexity may not justify the benefits.

Step‑by‑step: enabling Cloudflare APO for WordPress

  1. Create a Cloudflare account and add your domain. Point your DNS nameservers to Cloudflare to route traffic through their network. Cloudflare offers a free plan; APO costs $5/month.

  2. Install the Cloudflare WordPress plugin. This plugin handles automatic cache purges and ensures only appropriate pages are cached.

  3. Enable basic optimisations. Turn on automatic minification, Brotli compression and ensure “Always Use HTTPS” is enabled.

  4. Activate Automatic Platform Optimization (APO). This enables HTML caching at the edge and automatically purges caches when posts change. WisdmLabs notes that APO loads Google Fonts from the edge and purges the right page when content updates.

  5. Define cache bypass rules. Exclude /wp-admin, /cart, /checkout and other dynamic endpoints. Cloudflare’s plugin does this by default, but you can add custom page rules for membership or forum pages.

  6. Test anonymously and authenticated. Use a private browser or VPN to test from different regions. Compare TTFB and LCP before and after enabling APO.

Advanced: custom Workers for edge logic

If APO’s built‑in rules do not meet your needs, you can write your own Cloudflare Worker. A simple worker script can check for WordPress cookies and only serve cached HTML for anonymous users. For example:

addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
// Bypass for logged-in users or users with WooCommerce cart cookies
const cookie = request.headers.get('Cookie') || '';
if (/wordpress_logged_in_|woocommerce_items_in_cart/.test(cookie)) {
return fetch(request);
}
// Try to get response from edge cache
const cache = caches.default;
const cached = await cache.match(request);
if (cached) return cached;
// Fetch from origin and cache
const response = await fetch(request);
return new Response(response.body, response);
}

This pattern mirrors Cloudflare’s own APO logic: avoid caching requests that contain WordPress cookies and store HTML in the edge cache for everyone else. You can also use Workers KV to store metadata for purging or versioning, and Cloudflare’s fetch API supports streaming responses.

Pricing and ROI

Running WordPress at the edge is surprisingly affordable. WisdmLabs notes that Cloudflare Workers are free for up to 100 000 requests per day, then just $5/month for 10 million requests. APO for WordPress costs $5/month and includes HTML edge caching and font optimisation. For high‑traffic media sites this is a fraction of the cost of scaling servers or building a headless architecture. Kinsta’s integration with Cloudflare includes edge caching at no additional fee and allows you to clear caches from your dashboard.

The performance gains translate into real revenue. Faster page loads improve conversion rates and ad viewability. High cache hit rates (90 – 95 %) reduce server load and can lower hosting costs. By serving pages from the edge, you can handle traffic spikes like viral news events without overprovisioning origin servers. And because Cloudflare’s cache resides close to the user, it reduces carbon emissions by eliminating unnecessary travel across the Internet.

Conclusion: a smarter path than going headless

Deploying a headless stack (e.g., Next.js + GraphQL + custom API) is powerful, but it requires re‑architecting your whole site and adds maintenance overhead. For many publishers and e‑commerce stores, edge caching offers similar speed improvements without sacrificing WordPress’ editing experience. By leveraging Cloudflare Workers and APO, you can bypass PHP entirely for anonymous users, cut TTFB by seconds, and still serve personalised pages when needed. Combined with good hosting and database optimisation (see our guides on fixing WordPress server & database errors and improving site speed), edge caching positions your WordPress site to compete with single‑page apps on performance. Use our Speed Test: Your Site vs. Edge Cached Site lead magnet to see the impact yourself.

more insights

Get Proposal Form

Great! Let’s Find Out What’s Stopping Your Website From Performing at Its Best 🚀

🔍 We’ll Help You Identify What’s Holding You Back

You’ve already taken the first step — now let’s uncover what’s keeping your website from converting better. From slow load times to poor CTA placement, we’ll spot the bottlenecks and fix them.

💡 Why Are We Doing This For Free?

Because we know that once you see what a difference the right strategy makes, you’ll trust us for the execution too 😉
No obligations — just real, useful insights.

⚡ Let’s Get Started

Enter your details and we’ll send you a personalized audit within 24 hours — no spam, no fluff, just honest recommendations to make your site perform like it should.

Free Consultation Form (Yes/No Flow)

All good 😊 We’re glad you dropped by!
If you ever need a new website, Shopify store, or marketing help, reach out anytime at info@datronixtech.com.
Have a great day 🚀

Hey there 👋 Looking to build or grow your online presence?