Prerendered data
prerender() turns remote functions into static files at build time
Pattern Usage:
export const getBuildInfo = prerender(async () => ({
builtAt: new Date().toISOString()
}));
export const getTerm = prerender(
z.string(),
async (term) => ({ ... }),
{
inputs: () => ['query', 'form', 'command', 'prerender'],
dynamic: true // other terms are computed on demand
}
);
// usage is the same as query():
{(await getBuildInfo()).builtAt} Live Demo:
Build info (no arguments)
Reload the page: in production the timestamp stays the same until the next deploy.
Glossary (with inputs)
The first four are listed in inputs and prerendered; query.live is
not, so dynamic: true computes it at request time.
How it works: prerender() looks
like a query() to the component, but runs during vite build. The results are deployed as static
files, and the browser additionally caches them with the Cache API until the next deployment.
This works on pages that are otherwise dynamic (partial prerendering). Use it for data that
changes at most once per deploy, never for anything user-specific. In vite dev everything is computed on demand, so the timestamps change on every reload there.