Akshay Sura - Partner
24 Feb 2025
Next.js is a versatile framework that pairs exceptionally well with Sitecore XM Cloud, enabling developers to deliver seamless, headless digital experiences. Sitecore XM Cloud's composable architecture and Next.js's flexible rendering strategies provide a robust solution for modern web development. Let's explore Static Site Generation (SSG), Server-Side Rendering (SSR), Incremental Static Regeneration (ISR), and Client-Side Rendering (CSR) within the context of Sitecore XM Cloud, discussing their advantages, disadvantages, and how to use them effectively in a headless environment.
SSG pre-renders HTML at build time, creating static files that can be served from a CDN. When paired with Sitecore XM Cloud, it ensures lightning-fast delivery of content that doesn't change frequently.
export async function getStaticProps() {
const data = await fetch('https://your-sitecore-instance/api/content');
return {
props: { data },
};
}
SSR renders pages on the server for each request, fetching live data from Sitecore XM Cloud's APIs and delivering fully rendered HTML to users.
export async function getServerSideProps(context) {
const data = await fetch('https://your-sitecore-instance/api/content');
return {
props: { data },
};
}
ISR bridges the gap between SSG and SSR, allowing static pages to be updated incrementally at runtime. This makes it a powerful choice for Sitecore XM Cloud integrations. This is my favorite method for Next.js. Depending on your client's needs and where the sites are accessed, you may have to use reverse proxies if your website requests unusual ports or URLs that can be aborted on corporate firewalls. We had to end up using HA Poxy to solve the issue. This also allowed us to embed the authentication keys in HA Proxy instead of doing it on the client calls.
export async function getStaticProps() {
const data = await fetch('https://your-sitecore-instance/api/content');
return {
props: { data },
revalidate: 60, // Revalidate every 60 seconds
};
}
export default async function handler(req, res) {
await res.revalidate('/path-to-revalidate');
return res.json({ revalidated: true });
}
CSR fetches and renders content in the browser after the initial page load. While it's less common for Sitecore XM Cloud projects, it can be useful for highly interactive components.
import { useEffect, useState } from 'react';
function Page() {
const [data, setData] = useState(null);
useEffect(() => {
fetch('https://your-sitecore-instance/api/content')
.then((response) => response.json())
.then(setData);
}, []);
return <div>{data ? JSON.stringify(data) : 'Loading...'}</div>;
}
When integrating Next.js and Sitecore XM Cloud, Vercel's Data Cache efficiently reduces API calls and improves application performance. By caching responses from Sitecore's APIs, you can:
export async function getServerSideProps() {
const res = await fetch('https://your-sitecore-instance/api/content', {
next: { revalidate: 60 }, // Cache response for 60 seconds
});
const data = await res.json();
return {
props: { data },
};
}
By leveraging Vercel's caching mechanism, you can balance performance with content freshness, ensuring your application scales effectively while delivering an optimal user experience.
Combining Next.js with Sitecore XM Cloud opens up powerful possibilities for delivering headless digital experiences. Choosing the right rendering strategy—SSG, SSR, ISR, or CSR—depends on your application's specific performance, personalization, and content freshness requirements. By leveraging Sitecore XM Cloud's robust APIs and Next.js's flexibility, alongside tools like Vercel's Data Cache, developers can build scalable, efficient, and engaging applications tailored to their audience.
Do you have questions about integrating Sitecore XM Cloud with Next.js? Contact us today to explore how we can help you optimize your headless architecture!
Akshay is a nine-time Sitecore MVP and a two-time Kontent.ai. In addition to his work as a solution architect, Akshay is also one of the founders of SUGCON North America 2015, SUGCON India 2018 & 2019, Unofficial Sitecore Training, and Sitecore Slack.
Akshay founded and continues to run the Sitecore Hackathon. As one of the founding partners of Konabos Consulting, Akshay will continue to work with clients to lead projects and mentor their existing teams.
Share on social media