All posts

Converting static websites into a headless GraphQL suite

Static pages turned into a GraphQL API and modern frontends

A lot of companies still run on a pile of static pages. Every change goes through a developer, content is copied between files, and the site slowly drifts out of date. I’ve converted a few of these into a headless setup, and the difference is huge.

You can usually spot these sites from the outside. The footer still says © 2019. The “News” page has three posts, the latest one about a Christmas party. And somewhere inside the company there is a developer who sighs every time someone asks them to change a phone number, because that phone number is in fourteen HTML files.

What “headless” means

In a classic CMS the content and the design live in the same system. Headless splits them. The CMS only stores and manages content – the “body”. The frontend – the “head” – is a separate app that fetches content through an API and decides how it looks. The name is a bit dramatic, but the idea is simple: editors get an editor, developers get freedom, and neither gets in the other’s way.

The setup

  • Content lives in a CMS – often WordPress, because editors already know it.
  • One GraphQL API exposes pages, products and settings with exactly the fields the frontend needs.
  • A Nuxt frontend renders everything server-side, so it is fast and good for SEO.

Why WordPress? Not because it’s the coolest choice. Because the marketing team has used it for ten years and doesn’t want to learn something new. A headless setup where nobody wants to log into the CMS is just a very expensive static site.

query Page($slug: String!) {
  page(slug: $slug) {
    title
    blocks { type data }
    seo { title description }
  }
}

Why GraphQL

With a REST API, a page often needs five requests and gets back far more data than it uses. With GraphQL the frontend asks for exactly the fields it needs in one query, like the one above. It is also self-documenting – the schema tells you what exists – which makes onboarding a new developer a lot less painful. And when the frontend needs a new field, you add it to the query instead of waiting for a new endpoint.

How I migrate

First I map every static page to a content type and a set of blocks. Then I import the existing content with a script, so nothing is typed in by hand. The frontend is built block by block, and old URLs get redirects so search rankings survive the move.

The mapping step is where most of the thinking happens. Static sites are full of “almost the same” sections – a hero here, a slightly different hero there, a third one somebody made on a Friday. I try to merge those into a small set of flexible blocks. Fewer blocks means editors learn them faster and the design stays consistent. Twelve hero variants is not flexibility, it’s chaos with a nice font.

What can go wrong

  • Forgotten redirects – lose your old URLs and Google forgets you too.
  • Preview – editors want to see a page before publishing. Plan for it from day one.
  • Cache – fast pages are great until an update doesn’t show up. Clear the right cache when content changes.
  • Too much freedom – a page builder with no limits becomes 40 shades of blue very quickly.

What you get

  • Editors can update content without a developer.
  • The frontend is free to look and behave like a modern app.
  • One API that can also feed an app, a newsletter or anything else later.

This is the same approach I used for Elome, where WooCommerce still handles orders while the storefront is fully custom.

And the developer who used to sigh about the phone number? They get to build features instead. Everybody wins – except the © 2019 in the footer.