Intermediatenote 05 of 1103 reasons · 03 notes
Next.jsIntermediate
Cache fetches with revalidate
Use the fetch cache option to control ISR-style revalidation per request.
Code example
Copy, adapt, and ship.
Read the numbered lines, copy the complete snippet, then adjust the values for your project.
async function getPosts() { const res = await fetch("https://cms.example.com/posts", { next: { revalidate: 900 }, }); if (!res.ok) throw new Error("Unable to load posts"); return res.json();}Why this matters
The production reason.
- 01
Not every page needs live data on every request. Revalidation lets content stay fast while still updating on a predictable interval.
- 02
Use short windows for pricing or dashboards, longer windows for blog posts, docs, and tool landing pages.
- 03
This avoids rebuilding the entire site just because one data source changes.
How it holds up outside a demo.
- Next.jsUse revalidate on fetch calls, or export revalidate from the route.
- CMSUse webhooks for urgent updates and timed revalidation for normal changes.
- SEOStable cached pages are usually better than slow fully dynamic pages.
Explore other stacks
Jump into a different technology.
11 Next.js notes on this shelf, and six more stacks beside it.
Keep state close to the interaction
Local state avoids unnecessary parent renders and keeps component intent obvious.
Open the noteAbort stale fetch requests
Cancel outdated browser requests so fast UI changes do not render old data.
Open the noteBuild a CSS gradient generator with code export
A CSS gradient generator should preview color stops, preserve accessible contrast, and export clean CSS code.
Open the noteFix WordPress H1 SEO issues
Fix WordPress SEO issues by keeping one clear H1, escaping template output, and compressing images before WordPress upload.
Open the noteReduce LCP with image optimization
Reduce LCP with image optimization by resizing, converting, and compressing images before they reach production.
Open the noteUse real buttons for actions
If it changes state, use button. If it navigates, use a link.
Open the note