Stacks Horizon
All posts
Web & App Development2026-07-167 min readStacks Horizon

Building a Dynamic Blog: ISR and Fallback Content with API-Driven Articles

Discover how to design a high-performance, SEO-friendly blog that loads articles from an API using Incremental Static Regeneration (ISR) and effective fallback content strategies.

Building a Dynamic Blog: ISR and Fallback Content with API-Driven Articles

Building a modern blog that balances dynamic content, stellar performance, and robust SEO can be a challenge. Traditional server-side rendering (SSR) can be slow, while purely static sites require full rebuilds for content updates. This is where Incremental Static Regeneration (ISR) shines, especially when coupled with an API for content delivery and thoughtful fallback mechanisms.

The Challenge: Dynamic Content, Static Performance

Imagine a blog with hundreds or thousands of articles. You want new articles to appear quickly, existing ones to update without a full site redeploy, and all pages to load instantly for users and search engine crawlers. Fetching content directly on every request (SSR) can strain your server and add latency. Generating every page at build time (SSG) means every content update—even a typo fix—requires a complete rebuild and redeploy.

Enter Incremental Static Regeneration (ISR)

ISR, popularized by frameworks like Next.js, offers a powerful middle ground. It allows you to generate pages at build time (like SSG) but also update them incrementally after deployment, without requiring a full site rebuild. This means:

  • Fast initial load: Pages are served from a CDN, just like static assets.
  • Fresh content: Pages are regenerated in the background at defined intervals or on demand.
  • Scalability: Reduced load on your origin server compared to SSR.

How ISR Works with API-Driven Content

When building a blog with articles stored in a CMS or database and exposed via an API, ISR integrates beautifully. Here's a typical flow:

  1. Initial Build: During deployment, your application fetches a subset of articles (e.g., recent ones, or all if feasible) from your API and pre-renders them into static HTML files.
  2. User Request: A user requests an article page. If it's cached and fresh, the static page is served instantly.
  3. Revalidation: If the revalidate time has passed, the next request for that page will still serve the stale (but static) content immediately. In the background, your application will fetch the latest data from your API and regenerate the page. Subsequent requests will then serve the newly generated, fresh content.

Code Example: Next.js with ISR

Let's look at a simplified Next.js example for an [slug].js article page:

// pages/articles/[slug].js
import React from 'react';

export default function ArticlePage({ article }) {
  if (!article) {
    return <div>Loading article...</div>; // Fallback UI
  }

  return (
    <div>
      <h1>{article.title}</h1>
      <p>{article.content}</p>
      <p>Published: {new Date(article.publishedDate).toLocaleDateString()}</p>
    </div>
  );
}

export async function getStaticPaths() {
  // Fetch all possible article slugs from your API
  const res = await fetch('https://your-api.com/articles/slugs');
  const slugs = await res.json();

  const paths = slugs.map((slug) => ({ params: { slug } }));

  return { 
    paths, 
    fallback: true // See fallback content section below
  };
}

export async function getStaticProps({ params }) {
  const { slug } = params;
  const res = await fetch(`https://your-api.com/articles/${slug}`);
  
  if (res.status === 404) {
    return { notFound: true }; // Handle article not found
  }

  const article = await res.json();

  return {
    props: { article },
    revalidate: 60 // Revalidate article page every 60 seconds
  };
}

In this example:

  • getStaticPaths pre-defines which paths (article slugs) should be generated at build time. We fetch all known slugs from our API.
  • fallback: true is crucial for handling articles not listed in getStaticPaths.
  • getStaticProps fetches the actual article data for a given slug.
  • revalidate: 60 tells Next.js to regenerate this page in the background at most every 60 seconds if a request comes in.

The Importance of Fallback Content

When using fallback: true in getStaticPaths, not all pages are generated at build time. This is particularly useful for blogs with many articles, where pre-generating all of them might be too slow or resource-intensive.

Here's how fallback: true works:

  1. Known Paths: If a user requests a page that was pre-generated at build time (i.e., listed in paths from getStaticPaths), the static HTML is served instantly.
  2. Unknown Paths: If a user requests a page not pre-generated (e.g., a newly published article, or an older one you chose not to pre-generate), Next.js will:
    • Immediately serve a fallback version of the page (often a loading state).
    • In the background, call getStaticProps for that specific slug to fetch the data from your API and generate the full HTML.
    • Once generated, the browser receives the full HTML, and subsequent requests for that page will serve the static version.

Implementing Fallback UI

Inside your component, you can detect the fallback state using router.isFallback (if using next/router) or by checking if your props are empty, as shown in the ArticlePage example above:

// pages/articles/[slug].js (inside ArticlePage component)
import { useRouter } from 'next/router';

export default function ArticlePage({ article }) {
  const router = useRouter();

  if (router.isFallback) {
    return <div>Loading article content...</div>; // Show a loading indicator
  }

  // Render actual article content once props are available
  return (
    <div>
      <h1>{article.title}</h1>
      <p>{article.content}</p>
    </div>
  );
}

This provides a smooth user experience. The user sees something immediately, rather than a blank page, while the actual content is being fetched and generated.

Benefits of This Approach

  • Performance: Near-instant page loads for cached content, improving user experience.
  • SEO: Search engine crawlers receive fully rendered HTML, which is excellent for indexing and ranking.
  • Content Freshness: Articles can be updated on your API, and changes will propagate to your blog within the revalidate interval without manual redeploys.
  • Scalability: Offloads rendering work from your server to the build process and CDN.
  • Developer Experience: Simplifies deployment pipelines; content updates don't necessitate code deploys.

Conclusion

By leveraging ISR with an API-driven content source and carefully implementing fallback content, you can build a blog that is both incredibly fast and easy to maintain. This approach offers the best of both static and dynamic worlds, ensuring your readers always get fresh content with optimal performance and your site remains SEO-friendly and scalable. It's a powerful pattern for modern web development, especially for content-heavy applications like blogs and documentation sites.

Comments

Share your thoughts on this article.

Loading comments…