Deployments
Cache Policy
Treat HTML, route cache entries, generated assets, and public files as different cache surfaces. A single cache rule for everything will either make pages stale or waste the CDN.
Route HTML
Use route-level revalidate, cacheControl(), and revalidatePath() for rendered HTML. Keep personalized pages private or uncached.
import { cacheControl } from "@reckona/mreact-router";
export async function loader() {
cacheControl({
maxAge: 60,
staleWhileRevalidate: 300,
});
return { posts: await listPosts() };
}Do not cache route HTML that depends on Authorization, Cookie, per-user headers, or session state. Mreact skips shared route cache for requests with credentials, avoids storing responses that set Set-Cookie, and treats unknown request headers as private unless they are part of its public route-cache header allowlist. Your CDN and proxy rules must apply the same rule: cache only pages whose request headers cannot change the rendered user or authorization state.
Hashed client assets
Generated hashed route scripts, shared chunks, route CSS, and copied build assets can use a long immutable cache. If the filename includes a content hash, use immutable.
Cache-Control: public, max-age=31536000, immutableManifest files and source map upload directories are not the same as hashed public assets. Do not expose hidden source maps through the CDN.
Public assets
Files in public/ may or may not be fingerprinted. Give long cache headers only to filenames that include a content version. Use short cache or revalidation for files such as /favicon.svg, /robots.txt, and /manifest.webmanifest unless your release process versions them.
Static export
Static hosting turns prerendered pages into files. Cache static HTML conservatively unless the host has a reliable invalidation story. For GitHub Pages, assume HTML can be cached by browsers and intermediaries and keep asset filenames versioned.
Release order
- Upload new immutable assets before serving HTML that references them.
- Deploy server output or static HTML.
- Invalidate only HTML, manifests, and non-fingerprinted public files.
- Keep old immutable assets available until all live HTML can no longer reference them.