Background ISR
Opt public pages into a native HTML cache. Fresh entries serve immediately; stale entries keep serving the previous HTML while the server regenerates the page in the background.
export default {
swelte: { isr: { '/blog': 60 } }
}
// swelte build writes dist/isr.json.
// Runtime override: SWELTE_ISR=/blog=60Longest path-prefix match wins. The native server reads the policy from dist/isr.json; SWELTE_ISR overrides it at runtime. SSR must be enabled and the cache directory writable.
Request lifecycle
- A cold miss renders normally while scheduling background generation.
- A fresh entry serves immediately with
X-Swelte-Cache: HIT. - A stale entry serves the previous HTML with
X-Swelte-Cache: STALEand schedules one regeneration per key. - A successful render atomically replaces the cache file. A failed regeneration keeps the previous entry.
Cache hits expose Age and public Cache-Control with s-maxage and stale-while-revalidate. Up to four regenerations run concurrently per process;
shutdown tracks their work. Single-flight coordination is process-local.
Public page contract
Only anonymous, queryless HTML GETs use this cache. Cookies, Authorization, query strings,
JSON/navigation-data requests and ssr=false bypass it. Opt in pages whose anonymous
content is public and independent of request-specific headers.
Regeneration makes a fresh loopback request without credentials, through the normal guards and loads. Responses with cookies, explicit private/no-store policy, custom Vary, redirects, errors or an unrendered shell are not published. The cache stores the HTML body; load-specific response headers are not replayed on hits.
Cache ownership
Files live in dist/.swelte-isr, keyed by host, path and shell. A shell change selects
a new key, preventing obsolete asset references. The root SPA shell and application-owned static
files are not rewritten. Processes sharing a directory get atomic reads and replacement, while
each process schedules its own regeneration.