Set HTTP response headers from anywhere during server-side rendering - loaders, components, or middleware. Headers are accumulated and merged onto the final response.
The headers parameter is a standard Headers object.
Use setResponseHeaders in loaders to enable CDN caching and Incremental Static Regeneration:
app/blog/[slug]+ssr.tsx
Common cache header patterns:
s-maxage=3600 - CDN caches for 1 hourstale-while-revalidate=86400 - Serve stale content while revalidating in background (up to 1 day)max-age=0, must-revalidate - Always revalidate with originprivate, no-store - Never cache (for user-specific data)Note: stale-while-revalidate requires CDN support (Vercel, CloudFront, Fastly). Cloudflare does not currently support it.
Set cookies using the standard Set-Cookie header:
app/auth/login+api.ts
app/_middleware.ts
Edit this page on GitHub.