Is JAMstack Architecture the Future for CMSs?
The JAMstack approach towards developing websites aims to be as serverless as possible. It might remind us of the old days of web development when we delivered plain HTML and everything was simple and performant. Then JavaScript came to solve the problems of dynamic behavior and personalization. In time, JavaScript became so popular that we switched complete sites to client-side rendering, and started having performance issues, especially on mobile devices with slow connections.
JAMstack Architecture
JAMstack's approach tries to leverage the best of the old (static HTML) and new (dynamic JavaScript) worlds. The main difference between a classic CMS architecture and JAMstack is that only a small percentage of user requests need to reach the backend servers. Instead, all HTML/JS files are pre-built using popular tools for generating static sites like Gatsby, Hugo, or Next.js. The pre-built content is then pushed to a CDN like Vercel, Netlify, or CloudFront to achieve maximum performance. Naturally, we still need dynamic behavior on sites, so JAMstack sites can use JavaScript and APIs to talk to the backend services when needed. However, the goal should be to deliver as much static content as possible to boost performance.

Static Site Generation
Static Site Generation (SSG) is a variant of Server-Side Rendering (SSR) with one significant difference - content is pre-generated so client requests usually don't need to access backend systems. Instead, the backend system can send invalidation requests to the SSG tools to inform them that data has changed and that the content pieces need re-generation. This is typically done using cache tags, similar to how content invalidation is performed on the CDN level. When the SSG tools re-build the content, they should also invalidate/push the new content to the CDN. Therefore, only truly dynamic and personalized components need to be rendered client-side and send XHR/Ajax requests to backend systems.
Headless CMS
JAMstack architecture requires a headless CMS, as the head/frontend piece of the architecture should be decoupled to achieve SSG. Headless CMSs provide APIs for SSG tools to fetch the content structure, components, and data required for pre-building the site. Nowadays, many headless CMSs like Contentful, Storyblok, and Builder.io also provide visual editing capabilities. Visual editing usually requires a little bit of coupling between the CMS and the SSG tool, but it's a small trade-off when editors require WYSIWYG editing experience. Also, many headless CMSs are nowadays enterprise-ready and provide multi-site, multi-brand, multi-market, automatic translation, and rollout capabilities.
An Example
To demonstrate a simple JAMstack blog website, let's use Next.js as our SSG tool and Contentful as our Headless CMS. We'll start by creating a space in Contentful, defining a content model for a blog post, and filling it with some content.

Now, let's create a Next.js application based on the new app router and React Server Components. Our app should fetch the blog content from Contentful and pre-build two sites, one for listing blog posts and one for reading a single post. We'll add the required environment variables containing Contentful secrets and deploy our app on Vercel to leverage its CDN capabilities.

Next, we'll add a Webhook in Contentful to enable data cache revalidation in Next.js. On every blog post content change, Contentful will send a POST request to the Next.js app running on Vercel to trigger a rebuild of the blog pages. Without this webhook in place, we wouldn't see any content changes published in Contentful in our Next.js app.
Finally, we'll configure live preview settings in Contentful to enable editors to see unpublished content. For this, we'll leverage the Draft Mode API in Next.js and Contentful's Draft API. We should note that live preview in Contentful only works if HTML elements are enriched with the following attributes:
- data-contentful-field-id
- data-contentful-entry-id, or data-contentful-asset-id
- data-contentful-locale.
Without this feature in place, our editors wouldn't be able to preview unpublished content in Contentful's visual editor.

Now we should have everything in place to make both our editors and end-users happy. Since our demo site uses only server components, we expect it to perform fast even on mobile devices with slow connections. So, let's verify our app's frontend performance using Google PageSpeed. As shown below, our Next.js blog site is achieving great performance on mobile devices.

In case you want to explore more yourself, you can find the demo code on GitHub.
Conclusion
JAMstack is currently the most trendy and future-proof architectural choice for Headless CMSs. Besides the obvious performance gains, this architecture splits the layers nicely, enabling clients to choose different state-of-the-art solutions for their different layers. Therefore, each tool has a dedicated purpose, so their vendors can focus on their area of expertise and simply provide integration points with other state-of-the-art solutions. For example, most Headless CMSs have good documentation and tutorials for integration with Next.js. This approach makes a lot of sense and provides a good alternative to suite DXPs where one vendor tries to solve all issues.


