Skip to content
Be Useful.

Replatforming frameworks from Next.js to Astro (while the CMS stayed put)

Using AI to swap the framework and the host underpinning a live blog. Could we do it in one shot, like all the cool kids?

· 13 min read
A magician a split second after performing the tablecloth trick, striking a triumphant follow-through pose.

The tablecloth trick

The promise of a composable tech stack goes something like this. Your site is built from separate layers, a framework, a host and a headless CMS, and you can swap any one of them whenever you like. If it's done correctly, your readers won't notice anything has changed.

This month I tested that promise on Be Useful by replacing two of the three layers at once, with an AI model writing most of the code. The framework and host moved from Next.js (opens in a new window) on Vercel (opens in a new window) over to Astro (opens in a new window) on Cloudflare (opens in a new window).

Contentful, the headless CMS (opens in a new window) which hands content to any framework through its API, stayed exactly where it was.

On switch day, moving visitors to the new site took a single click in a dashboard. Every URL answered as it had the day before, page heights matched to the pixel, and no page differed by more than 0.03% of its pixels.

It was like whipping a gingham tablecloth from a set table without a single plate wobbling. AND THEN I added in an entirely new tablecloth, this time with a fetching paisley pattern.

Why move at all?

Not because anything was wrong. Next.js and Vercel ran this site very well indeed, and I have zero complaints about the experience. Moving to Astro on Cloudflare was approached more as a challenge than as a fix. I was curious to see how far I'd get with AI handling the coding.

What compelled me to do it now was a run of stories on Reddit and elsewhere. Folks claim to have used AI models to "one-shot" complex problems, solving them with a single prompt. I was given temporary access to Claude Fable, a top-tier model offered by Anthropic, and replatforming the site seemed like an ideal test.

I'll admit the one-shot stories gave me false confidence. I expected it to take fewer steps than it did. Whether it really was "done in one" will become apparent as I tell my story.

The plan

Did you know? Every request this site makes to Contentful goes through a single file, lib/api.ts. Nothing else in the code knows the CMS exists.

The API is the key a composable stack depends on, and keeping every call to it in one file meant the move was a job for the framework and the host only. No content migration necessary: not a single post or asset had to be exported, converted or re-entered.

The rest of the plan followed from having an escape hatch at every step.

  • Build alongside. The new site went into a new repo (opens in a new window), parallel to the old one (opens in a new window), starting as a bare Astro skeleton and the file that talks to Contentful. The old site stayed live until the new one matched it. If the experiment had stalled, readers would be oblivious to the buffoonery behind the scenes.

  • Hardest parts first. Fable got a brief for each, starting with preview mode, then the rich-text renderer and post page, then social cards, then a script to compare every URL on both sites. Each step had to be stand-alone, so if access to Fable ran out midway through the changeover, the next model could pick up where it stopped.

No vestiges

One line in the first brief had the greatest significance, in my estimation. In bold, it told the model to "build it the way an experienced Astro developer would, not the way the old site happened to be built."

The old repo described what the site had to do, not how to do it. Anything a well-maintained official tool already did, the model was forbidden from reinventing. And any rule that only existed because of Next.js or Vercel was to be dropped.

The result reads like a site that was always built in Astro.

  • There's no UI framework at all. The old site's pages were React components. The new one has no React dependency, and its only Astro packages are the Cloudflare adapter and the type checker.

  • Fonts use Astro's built-in font feature instead of hand-wired files.

  • Readers are sent none of the site's own JavaScript files. More on that later.

  • Nothing in the repo names the old framework or host.

Describing the kind of developer required for the task, as opposed to just the task itself, influenced what came back. This is anecdotal evidence on one project, so I can't claim this will always help. But it worked here.

The rules the model follows were written afresh too. The new CLAUDE.md is 192 lines, each rule with its reason in a line or two, and there's no decisions log. About a quarter of the old log's 56 entries explained how Next.js worked, and most of the rest pointed at files that no longer exist.

(The postscripts of The weight of standing agent instructions and Eliminating cruft from the codebase tell the same story.)

The build

1. Preview mode

This was the go or no-go test, so it came first. Preview lets me open a draft from inside Contentful before it's published.

The old site did a lot of sophisticated things. It checked a secret, checked the slug's format, refused slugs it didn't recognise, switched to German for translated posts, and worked inside Contentful's side-by-side preview frame.

The new one had to manage all of that while on a different framework and a different host. It passed with flying colours, which meant the rest of the port could proceed.

2. Pixel parity

"Readers shouldn't notice" is easy to say and hard to check, so the first pull request verified it. It took full-page screenshots of both sites and compared them pixel by pixel, at three widths, in light and dark mode.

Every page height it checked matched exactly. The most any page differed was 0.03% of its pixels, all of it in text smoothing and the resampling of small portraits.

It also caught something about the old site. My post titles were meant to be 76px on large screens. They had always shown at 60px, because the style rule asking for 76px was never actually generated. Yikes. At least now the new site matched what readers had been seeing all along, rather than what the old code asked for.

3. Social cards

The images that appear when a post is shared went from about 783 KB each to about 84 KB, around a tenth of the weight. The new site draws them when it builds and saves them as JPEGs rather than PNGs.

4. Guard parity

Tests are automatic checks that run every time the code changes, confirming, for example, that preview mode checks its secret or that the security headers are sent.

The old repo had 65 test files, and Fable went through every one. Tests that only checked how Next.js did things were dropped. Tests guarding what the site has to do were rebuilt.

The new site has 26, and they follow a simple rule. Test only what a look at the page would miss, such as server code, publishing, feeds, metadata and accessibility. Layout and on-page behaviour I check by eye.

Switch day

1. The runbook

Claude kept a runbook for the move, a written plan I could follow and tick off. It was written for me as steps to follow in the Cloudflare and Contentful dashboards, with no code to worry about.

Every step ended with a test, so a mistake showed up straight away rather than days later. The way back was written down before the switch, as clicks I could do myself.

And it stayed current, with each step crossed off and dated, and anything new added as an open item.

2. Two moves, not one

The switch was split into two stages. First, Cloudflare took over the domain's DNS (the records that tell browsers where to find the site) while the old site carried on serving pages. Then one click attached beuseful.net to the new site. Until the old project was retired, going back was one click, too.

There was just one snag. Cloudflare refused to attach the domain while it still held the old records, with the message "Hostname already has externally managed DNS records". Deleting the two old records first fixed it.

Afterwards came the checks. Sitemap, feed, search, redirects and preview all worked, and the script comparing every URL on both sites found zero differences. It worked!

Ah, but there was one thing the new site couldn't do yet. Every time I published, it rebuilt the whole site, which took about 70 seconds.

Whither art thou, instant publishing?

Seventy seconds sounds like nothing. I've dealt with worse. I've experience of one framework where every publish triggered rebuilds for the entire site, and fixing a typo meant waiting long enough to boil the kettle and brew a mug of tea. But I'd grown to appreciate the Next.js way of doing things.

The old site had a feature called on-demand revalidation (opens in a new window) (one of Next.js's flavours of Incremental Static Regeneration (opens in a new window)). When I published a post, Contentful told the site, and the site regenerated just the pages that post appeared on, within seconds. The rest stayed as they were.

The new site had nothing like it on switch day. I wanted it back.

1. The pieces

The fix was built a day after the switch, and every piece of it was new.

  • Route caching in Astro. This feature arrived in Astro 7. (opens in a new window) It lets a page be rendered when it's first asked for, then kept until something says it's out of date. The part that connects it to Cloudflare is labelled experimental in Astro's own docs.

  • Workers Cache on Cloudflare. This is what actually keeps the pages. (opens in a new window) Cloudflare launched it in July 2026. It puts Cloudflare's cache in front of the site's code. If a saved copy of a page exists, Cloudflare serves it and the code never runs. If not, the code renders the page once, and Cloudflare keeps that copy for every visitor after.

  • A purge webhook from Contentful. When I edit or publish something new, Contentful calls a private address on Be Useful, which clears only the pages this change touches. Every cached page is labelled with the posts, authors and images it shows, so the site knows exactly which ones to clear.

2. The result

I changed a post's title in Contentful and published it. It was live in seconds, before the rebuild had even finished. The full rebuild still runs afterwards as a safety net, refreshing search, the feed, the sitemap and the social cards, and clearing the cache again in case anything was caught mid-update.

3. The catch

There is a catch, and it's the price of building on new parts. The site runs on Cloudflare's free plan, which allows ten milliseconds of processing per request. A page that isn't cached yet takes about 22. Cloudflare tolerates going over now and then, but I watched it daily for a week to make sure. Uncached pages went over the limit a few times a day, and Cloudflare never refused a single one.

If the free plan turns out to be inadequate, I'm not sure that I care enough about instant publishing to pay for the luxury. I can turn it off with one setting, and the site goes back to plain static files and 70-second publishes. But the code stays in place, tested and ready to call into service if needed.

The first week

The tidying up was routine. The www address now redirects to beuseful.net, the temporary staging copy of the site is switched off, and the sitemap has been resubmitted to Google and Bing. The forkable template moved across to the new repo too, and a test fork was built cleanly on an empty Contentful space. Pay it forward has the details.

The posts about the old site

A site that writes about building itself has a problem when it rebuilds itself. A whole run of posts on this blog described the old stack, and after the move, some of them were no longer accurate.

Each of those posts has two jobs. It has to stay useful to someone following it today, and it has to stay an honest record of what I did at the time. The two pull against each other, and walking that line is bloody difficult.

Where a post explains how something works, I've rewritten it to be true now, under an updated date. Static site search and Pay it forward are two of those. Where a post records what happened on a particular day, the body stays as it was, with a postscript or a short editor's note pointing here.

It's the one place a reader could actually notice that anything changed at all: it's in the writing, not the site.

So, was it really one shot?

No. It was pretty damn quick, though. The new repo was empty on 14 November, and beuseful.net was running on it the next day. But by 20 November there had been 38 pull requests (proposed changes) reviewed and merged.

The model wrote nearly all of the code, and wrote it quickly. What made the move safe was everything around it. That meant a brief for every step, a pull request for every change, independent audits before and after the switch, and the runbook.

One-shot is the wrong question. Better to ask whether the model you choose can work inside a process you can verify. In this instance, Fable was able to chew through the code without difficulty.

What got better

The biggest change is what readers download. I measured the home page and one post, the Pi-hole guide, on both sites. The old figures come from the first pull request on 14 November, and the new ones from the live site on 20 November. Both are compressed bytes as sent, and both leave out analytics scripts.

a. Home page

File type

Old (KB)

New (KB)

Change

JavaScript files

183.1

0

-100%

CSS

16.8

13.3

-21%

HTML

14.1

8.4

-40%

Fonts

212.4

216.6

+2%

Total

426.4

238.3

-44%

b. Pi-hole post

File type

Old (KB)

New (KB)

Change

JavaScript files

186.3

0

-100%

CSS

16.8

13.3

-21%

HTML

37.6

25.4

-32%

Fonts

326.9

329.7

+1%

Total

567.6

368.4

-35%

The site's own JavaScript files went from about 183 KB to none, and each page is 35 to 44% lighter overall. To be fair to Next.js, that's my old build against my new one, and the old one already kept everything it could on the server. What it couldn't shed was React itself, which Astro doesn't need.

The few small scripts the site still needs, for the copy buttons, the lightbox and the menu, now sit inside the page itself. That's 1 to 5 KB before compression, and it's already counted in the HTML row.

Fonts are the one number that went the wrong way, by 1 to 2%. I haven't dug into why. They now make up about 90% of what each page sends, so they're the obvious place to look next.

Anyhow, these savings matter more than the raw bytes suggest. A browser has to run JavaScript on the same thread that responds to taps and scrolls, which makes it costlier than images or text of the same size. The old site already sent finished pages, so on a fast phone the difference is small. On a cheap phone or a slow connection, it should be bigger (I measured bytes, not speed, so that part is an educated guess).

Two other things improved. Social cards are about a tenth of their old weight. And the free Cloudflare plan serves static files at no cost, however many people visit (with the catch I described above for pages that aren't cached yet).

If you're considering replatforming

  • Use a headless CMS with a proper API, and keep every call to it in one place. Then a framework move stops being a content move, and moving back stays possible too.

  • Build alongside, switch at the end. Keep the way back one click away until you're sure.

  • Move the DNS and the site in separate steps, so only one thing can go wrong at a time.

  • Decide in advance what "matches" means. Mine was zero differences across every URL.

  • Tell the model what kind of developer to be, not just what to build. The old code shows how it was done, which can be a straitjacket.

  • Ask for a runbook you can follow, with a test at the end of every step.

  • Experimental features are fine on a personal site if there's a kill switch.

The verdict

Does the composable promise hold? Mostly, and the line between what travelled and what didn't is clear.

Content moved without a hitch. Contentful serves everything through its API, and every call to it sits in one file, so the framework and the host could both change without touching a post, an asset or a URL.

Instant publishing didn't travel. It was built into the old framework and host, so it had to be reimagined from an experimental Astro feature, a new Cloudflare cache and a webhook, and uncached pages still run over the free plan's processing limit.

And Fable didn't one-shot the move. With clear briefs, automated checks and a way back at every step, it didn't need to.

Astro and Cloudflare need a few more weeks before I pass judgement on the new paisley tablecloth, and the old repo is archived if I change my mind. No objections so far. Composability FTW!

Voilà
Hand-painted gouache illustration on textured paper, mid-century magazine style, eye-level view from a seat at the dinner table. Across the table a magician in a black tailcoat and red waistcoat, friendly natural face, a split second after the tablecloth trick, striking a triumphant follow-through pose, one arm flung back and out behind him at shoulder height, the other hand open towards the table in a "voilà" gesture. A red and white gingham tablecloth trails out from his raised hand, still rippling and flapping in the air from the momentum. In front of him the bare wooden table, two plates, two wine glasses and a wine bottle standing perfectly upright and undisturbed. Plain deep teal wall with one soft shaft of warm golden light. Clean, uncluttered composition. Palette of teal, warm gold, red, cream and pale blue glass, visible brushwork, matte opaque colour.

written by

Bulent Yusuf

Bulent is a content marketer by trade and writes everything here that isn't films or games (which turns out to be most of it). He doesn't think speaking about himself in the third person is the least bit weird. Born in the UK, Turkish Cypriot heritage, living in Germany.

More from Bulent Yusuf →

more like this