Paul LovellBook a call
Back to Blog
5 min readPaul Lovell

Edge Schema Injection via Cloudflare Workers

Deploying schema through a legacy CMS often means a developer ticket queue. Injecting it at the edge skips that entirely.

Technical SEOStructured Data

Deploying JSON-LD on a legacy CMS often means waiting on a developer release cycle for something that's really just a content change. Injecting structured data at the CDN edge with Cloudflare Workers (or an equivalent NGINX layer) lets you parse backend data and add JSON-LD directly into the HTML head before the response reaches the crawler — without touching CMS code at all.

A minimal injection worker

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

async function handleRequest(request) {
  const response = await fetch(request)
  const contentType = response.headers.get('content-type')

  if (!contentType || !contentType.includes('text/html')) {
    return response
  }

  const schemaData = {
    "@context": "https://schema.org",
    "@type": "Article",
    "headline": "Edge Schema Injection Guide",
    "author": { "@type": "Person", "name": "Paul Lovell", "url": "https://www.paullovell.uk" }
  }

  const jsonLdScript = `<script type="application/ld+json">${JSON.stringify(schemaData)}</script>`

  return new HTMLRewriter()
    .on('head', {
      element(element) {
        element.append(jsonLdScript, { html: true })
      }
    })
    .transform(response)
}

Why this is worth doing

Schema updates deploy globally within seconds via CDN rules rather than a release pipeline, and because the injection happens on the raw HTML response, the JSON-LD is present during the crawler's first pass — no JavaScript execution required to see it. The tradeoff is that this markup now lives outside your CMS, so it needs its own change log and testing discipline rather than inheriting the CMS's.

Paul Lovell

Written by

Paul Lovell

International SEO Consultant & Founder of Always Evolving SEO. 15+ years running technical audits, log-file analysis, and root-cause fixes for multimillion-dollar businesses — speaker at SMX London, Search & Content Summit, and SEMrush events.