Skip to main content
Reggie Pangilinan
HomeBlogAbout
GitHubLinkedIn

© 2026 reggiepangilinan.com All rights reserved.

GitHubLinkedIn
Instant Cache Updates Without Full Rebuilds: On-Demand ISR…
←Back to Blog

Instant Cache Updates Without Full Rebuilds: On-Demand ISR with Contentful Webhooks in Next.js 16

How a single /api/revalidate endpoint keeps 24-hour cached blog posts, the blog index, and sitemaps fresh the second you click Publish.

December 2, 2026·Reggie Pangilinan·2 min read
Instant Cache Updates Without Full Rebuilds: On-Demand ISR with Contentful Webhooks in Next.js 16

Long ISR cache windows are awesome for speed and staying well inside free-tier limits—until you spot a typo five seconds after publishing a post. 😅

On reggiepangilinan.com, individual blog posts cache for 24 hours (revalidate = 86400). Waiting a full day (or triggering a full Netlify site rebuild) for a one-word fix wasn't going to cut it.

The sweet spot is pairing a 24-hour ISR fallback with on-demand webhook revalidation so Contentful tells Next.js the exact paths to refresh the moment an entry changes.


⚡ 1. How the Webhook Flow Works

Instead of polling Contentful every few minutes, the update is event-driven:

  • You click Publish (or Unpublish) on a blogPost entry in Contentful Studio.

  • Contentful fires a POST webhook to /api/revalidate with the shared REVALIDATION_SECRET, contentType, and slug.

  • The route handler validates the secret and sanitizes the slug, then calls Next.js's revalidatePath() across every affected route.

  • Netlify serves fresh HTML on the very next request—no full build required.

On-Demand ISR Revalidation — Next.js 16
On-Demand ISR Revalidation — Next.js 16

🔒 2. Validating Secrets & Sanitizing Logs

Webhook endpoints are publicly reachable URLs, so keeping src/app/api/revalidate/route.ts clean and defensive matters:

  • Secret verification: Every request must include a secret matching process.env.REVALIDATION_SECRET. If the env var is missing, it returns 500; if the secret doesn't match, it returns 401.

  • Never log secrets: When logging incoming webhook payloads for debugging, the handler strips the raw secret and only logs hasSecret: Boolean(secret). That way, Netlify function logs stay useful without ever leaking credentials.

  • Strict slug validation: Incoming slugs are trimmed of leading/trailing slashes and checked against /^[a-zA-Z0-9\-_]+$/. If a malformed or missing slug arrives, it safely falls back to revalidating /blog at the layout level instead of failing silently.


🌊 3. Cascading Invalidation (More Than Just One URL)

A common mistake with on-demand ISR is only calling revalidatePath('/blog/' + slug) and forgetting every other route that references that post.

When a blogPost webhook arrives, src/app/api/revalidate/route.ts cascades invalidation across:

  • The post itself: revalidatePath('/blog/' + cleanSlug) and revalidatePath('/blog/' + cleanSlug, 'page')

  • The blog index: revalidatePath('/blog') and revalidatePath('/blog', 'layout')

  • SEO & crawl routes: /sitemap.xml, /sitemap-isr.xml, and /robots.txt

It also supports manual type: 'path' and type: 'tag' (revalidateTag(tag, 'max')) payloads if I ever want to clear a specific route or cache tag by hand.


🕒 4. Keeping the 24-Hour Fallback in Sync

Even if a webhook ever drops or fails during a transient outage, src/app/blog/[slug]/page.tsx still has export const revalidate = 86400 and export const dynamicParams = true as a safety net.

Because Next.js requires revalidate to be a static literal in page files, I keep the expected timing documented in src/config/isr.ts and call ISR_CONFIG.validatePageRevalidate('blog-post', revalidate) so any drift shows up immediately.


✨ Wrapping Up

Combining 24-hour ISR with a tiny, defensive webhook handler gives you static-site speed, minimal CMS API calls, and near-instant edits—all without waiting on full CI/CD rebuilds every time you fix a sentence.

You can check out the complete implementation in src/app/api/revalidate/route.ts on GitHub.

Keep Reading

Related Posts

December 3, 2026

Adding AI-Powered Blog Search with Google Gemini in Next.js

How we added an intelligent, Gemini-powered search bar to a Next.js + Contentful blog—covering AI basics for non-specialists, why hybrid search beat Google Search Grounding and Vertex AI Search, real-world free-tier traffic estimates, and built-in cost guardrails.

Next.jsTypeScript
December 3, 2026

Running a Full Next.js Blog on Free Tiers: A Contentful + Netlify Case Study

A data-backed case study breaking down Contentful Free, Netlify Free, and GitHub Free quotas (at the time of this writing), with real math on how many visitors, blog posts, and images a personal site can serve before ever paying a cent for infrastructure.

Next.jsContentful
December 2, 2026

Four Silent Sitemap & SEO Bugs I Found Auditing My Next.js 16 Blog

What sitemaps, robots.txt, and canonical URLs actually do for search indexing—plus four silent SEO bugs I found and fixed auditing my Next.js 16 + Contentful blog.

Next.jsSEO
Topics
Next.jsISRContentfulNetlifyWebhooks

Share this article

Found this helpful? Copy the link or scan the QR code to share it.

←All blog posts