Topics

Partially implementing a CMS on an existing site using "post-processing SSR" (Notes on using Cloudflare Pages Functions + microCMS)

  • column

Hello, I'm Otsuka, CTO at Liberogic.

Even if you tell me to do something about the article...

So, I thought I'd leave a little technical note about "partially implementing a CMS on an existing website."

In the past, the standard approach was to use PHP to "inject logic into HTML," but now, by using Cloudflare Pages Functions, you can create a much smarter, SEO-friendly structure that can be properly indexed by Google.

This time, I'll share how I integrated a microCMS into a static site built with Eleventy by applying "post-processing SSR" using Cloudflare Pages Functions.

Key points of this configuration

In this project, we are building the frontend using Eleventy + Nunjucks. Unlike Astro, which encapsulates Functions within the project,dist/We adopted a method where dynamic content is inserted later into the static HTML output.

It's surprisingly easy to handle and convenient.

1. I want to apply Basic authentication only to the preview environment.

The requirement was, "We want to include authentication in the preview environment, but we want to minimize the execution (cost) of unnecessary workers in production." So, we made a slight adjustment to the pre-build processing,Only during the production build_middleware.jsThe process involves deleting it.

In the production environment, authentication is not required, thus balancing security and convenience while minimizing unnecessary execution costs.

2. Cache microCMS responses using the Cache API.

When using SSR (Server-Side Rendering), one of the biggest concerns is the load and latency caused by making API calls with every request.

That's Cloudflare'sCache APIWe decided to use this method to cache the response at the edge. The cache TTL was set to a relatively short duration of about 5 to 10 minutes.

We maintain freshness while ensuring excellent performance.

3. Cache purging (revalidate) using KV

Even though the TTL is short, the fact that updates aren't reflected instantly is a bit stressful for the operations team.Cloudflare KVWe used it as a store for controlling the revalidate process.

The mechanism is simple.

  • When an article is updated using microCMS, a webhook is triggered.
  • The KV value is updated at that time.
  • Pages Functions uses the KV value as a trigger to determine whether to invalidate the cache.

This design offers the best of both worlds: "blazing fast updates thanks to caching, and instant updates."

summary

I like this approach of "leveraging the strengths of existing static sites while modifying only the necessary parts with Edge" because it offers a high degree of operational flexibility.

Recreating the ease of use of old PHP with the power of Cloudflare! While flashy framework migrations are nice, these kinds of "down-to-earth improvements" are actually the most useful in real-world situations.

Well then.

Written by

The backbone of the Liberogic Technology Department. Whenever he hears someone say, "I wish I had something like this, it would be so convenient," he uses his ingenuity to add value and implement it in no time. He is a treasure of our company with great communication skills and many loyal customers, and he also loves cats.

Kakeru-san

CTO / Chief Engineer / CEO of Nekoana Inc. / Looks unnecessarily young

View this staff member's article

We pride ourselves on our reliable team structure and speedy response capabilities.

At Liberogic, our experienced staff proactively drive projects forward, which is why we are highly regarded by our clients.
We ensure that project managers and directors are properly assigned to ensure the smooth progress of the entire project. We prevent unnecessary cost increases from full commitments and allocate resources to the right people in the right places, and are well-known for the speed with which we can grasp the work content, create and submit estimates.

Please note that we do not actively engage in SES-style on-site work.

We support almost all major project management and chat tools, including Slack, Teams, Redmine, Backlog, Asana, Jira, Notion, Google Workspace, Zoom, and Webex.

In large-scale projects using SES and offshoreDo you have any technical issues or concerns about how to tackle them?

Case Study