Edge SEO with Cloudflare Workers: inject metadata without touching your CMS
9 min read
What is edge computing?
Edge computing means running code at network nodes that are geographically close to users โ rather than in a centralized data center. Cloudflare operates over 300 points of presence worldwide. When a user in Berlin requests your Italian website, a Cloudflare Worker can intercept that request and process it at a data center in Frankfurt, before forwarding it to your origin server in Milan.
From the user's perspective, this is imperceptible โ the response arrives in milliseconds. But between the user's request and the origin server's response, your Worker has the opportunity to inspect the request, modify the response, inject content, route to different backends, and apply complex logic โ all without any changes to your origin infrastructure.
How Cloudflare Workers intercept HTTP requests
A Cloudflare Worker is a JavaScript (or TypeScript, or WebAssembly) function that runs in response to HTTP events. The basic pattern is: receive a request, optionally modify it, forward it to the origin, receive the response, optionally modify it, return it to the user.
Workers run in V8 isolates โ not Node.js, not containers โ which means startup time is typically under 1 millisecond. There is no cold start penalty. Every request hits a Worker that is already running at the nearest Cloudflare data center.
Why injecting SEO at the edge is better than in the CMS
Three reasons make edge injection superior to CMS-level SEO for international use cases:
- Zero latency overhead โ The Worker runs at the same data center serving the request. Adding hreflang tags to an HTML response adds approximately 1ms of processing time. A CMS plugin doing the same work on the origin server may add 50โ200ms.
- Works with any stack โ A Worker sits between the user and your origin. It doesn't care whether your origin runs Shopify, Siteground shared hosting, Squarespace, or a static HTML file. The origin doesn't even know the Worker exists.
- Centralized control โ Change the hreflang configuration in one place, and it applies to every page on every language subdomain simultaneously. No need to redeploy the CMS, clear caches, or touch individual page templates.
A real Workers script: inject title + hreflang
Here is a simplified but functional Cloudflare Worker that intercepts a response and injects hreflang tags into the HTML head:
This script fetches the origin HTML, appends hreflang tags before the closing </head> tag, and returns the modified response. Every page on the site gets hreflang injected โ without touching the CMS, without a plugin, without a developer accessing the server.
The KV cache pattern: pre-generate metadata, serve at 1ms
The script above fetches the origin on every request and modifies the response in real time. For high-traffic sites, a more efficient pattern is to pre-generate the SEO metadata (titles, descriptions, hreflang) using a scheduled job, store them in Cloudflare KV, and read from KV on each request.
Cloudflare KV is a distributed key-value store that is globally replicated across all Cloudflare data centers. A read from KV takes approximately 1ms. This means the Worker can inject pre-computed, AI-optimized SEO data without any computational overhead on the request path.
The pattern: a nightly scheduled Worker crawls your site, extracts content, generates optimized titles and descriptions using Claude AI, and writes them to KV. The request-handling Worker reads from KV and injects the pre-computed metadata. The result is SEO optimization at the speed of a cache read.
Limitations: Workers CPU time limits, KV consistency model
Cloudflare Workers have a CPU time limit of 50ms per request on the free plan, 30 seconds on paid plans. For simple string replacement operations (injecting hreflang, replacing title tags), this limit is never approached. For complex parsing or AI inference at runtime, it would be a constraint โ which is why the KV cache pattern pre-computes everything.
Cloudflare KV uses an eventual consistency model โ updates propagate across all data centers within 60 seconds. For SEO metadata that changes nightly, this is irrelevant. For applications that need immediate consistency (such as pricing or inventory), KV is not the right tool.