Menu

1 / 2

Stop Hitting the Sanity API on Every Request: Build Smart Caching with Next.js ISR and Webhooks

DEV Community: nextjs·Jay Patel·11 days ago
#gphfQgbN
#devtonextjs#devto#dev#sanity#tags
Long article (2229 words) — no AI summary yet.
Reading 0:00
15s threshold

Your blog feels fast in development. Then real traffic arrives, and every page view sends a fresh GROQ query to Sanity. Response times grow, the API usage chart climbs, and nobody chose this on purpose. It happens when fetch calls have no cache plan.

Sanity caching in Next.js fixes this by storing query results and clearing them only when content changes. In this guide, I share the setup I use for read-heavy sites. It uses ISR as a safety net, cache tags for precision, and a signed webhook that refreshes pages seconds after an editor clicks publish. If you want help applying this to a live product, our full stack development services cover Next.js and headless CMS builds.

We will build it in layers: a folder structure, a cached fetch helper, tag design, a webhook route, database logging, error handling, and a production checklist. The code targets Next.js 15 and 16 with the next-sanity package.

Understanding the Request Flow of Sanity Caching in Next.js

A visitor opens a post.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.