cacheControl option to Sonamu’s SSR routes.
Basic Usage
Adding to registerSSR
SSR Caching Strategy
SSR Preset
The most recommended approach is usingCachePresets.ssr.
How It Works
Benefits:- Most requests get instant response (CDN cache)
- Fast response even during stale period
- Background updates keep content fresh
Strategies by Page Type
- Dynamic Pages
- Semi-dynamic Pages
- Static Pages
- Personalized Pages
Frequently changing content
Practical Examples
1. E-commerce Site
2. Blog
3. SaaS Dashboard
CSR Fallback
All requests that don’t match SSR routes are handled by CSR fallback.Global Handler
You can apply Cache-Control to all SSR pages at once.Using SSRRoute Object
Priority Order
SSR Cache-Control settings are applied in the following order:- registerSSR’s cacheControl (highest priority)
- cacheControlHandler return value
- Default (no Cache-Control header)
Vary Header
Use Vary header for multi-language SSR pages.CDN Optimization
CloudFront + Stale-While-Revalidate
AWS CloudFront supportsstale-while-revalidate.
- Browser: Requests CDN every minute
- CDN: Requests server every 5 minutes
- Stale: Fast response for up to 15 minutes (5 min + 10 min)
Combining with Static Assets
- HTML: Updates every 10 seconds (fresh content)
- JS/CSS: 1 year cache (fast loading)
Preloading and Caching
Combine SSR’spreload feature with Cache-Control.
- During SSR: Preload data on server → Generate HTML → Cache
- Cache hit: CDN returns HTML instantly (fast)
- Hydration: Client uses preloaded data