Prompt
How do I refresh programmatic pages when my source data changes
Latest observation
To refresh programmatic pages when your source data changes, you generally want the pages to be regenerated or invalidated automatically instead of waiting for a manual rebuild.
The best approach depends on how your pages are built:
1) If you use SSR or dynamic rendering
If pages are rendered on each request, they’ll naturally reflect the latest data as long as your server fetches fresh data.
- Pros: Always current
- Cons: More load, potentially slower
2) If you use static generation
If pages are generated ahead of time, you need a refresh strategy:
A. Rebuild on a schedule
Run your build pipeline periodically.
- Good for data that changes occasionally
- Simple to set up with cron / scheduled CI jobs
B. Use on-demand revalidation / cache invalidation
When your source data changes, trigger regeneration of only the affected pages.
Typical flow:
- Source data changes
- A webhook or event fires
- Your app invalidates the relevant page cache
- The page is regenerated the next time it’s requested, or immediately if your framework supports it
This is often the best option for programmatic pages.
C. Use incremental/static regeneration
Only refresh pages that need it, instead of rebuilding everything.
This is especially useful when you have:
- lots of pages
- frequently changing content
- expensive builds
3) Trigger refresh from your data source
If your source is a CMS, database, or API:
- emit a webhook on update
- listen to database change events
- use message queues/events
- call your app’s revalidation endpoint
4) Invalidate caches properly
If your pages depend on cached API responses, CDN content, or app-level cache, make sure you invalidate all layers:
- application cache
- page cache
- CDN cache
- browser cache, if needed
5) Use cache headers carefully
For dynamic content, set headers so pages/data expire appropriately:
Cache-Controlstale-while-revalidateETag/If-None-Match
Practical recommendation
For most programmatic pages:
- use static generation
- add on-demand revalidation
- trigger it with a webhook or data-change event
If you tell me your stack — for example Next.js, Nuxt, Astro, SvelteKit, Gatsby, Hugo, or custom — I can give you the exact implementation.