Guide › Introduction
Rendering modes
Each route chooses when it renders. The default is at build time; routes that depend on the request render on the server instead.
| Mode | Renders | load() runs | Good for |
|---|---|---|---|
static | once, at build, to an HTML file | once per page, at build | docs, blogs, marketing pages |
server | on every request, by the server | on every request, with the request | accounts, search, anything per visitor |
client | in the browser, by the router | once per page, at build (served as __data.json) | app-like sections where moving between pages shouldn't reload; see Client routes |
Choosing a mode
List the routes that aren't static in the plugin options. A folder pattern such as /account/* covers the folder and everything under it; the most specific pattern wins.
// vite.config.ts
clarusjs({
routes: {
'/account/*': 'server',
'/account/help': 'static',
},
})Server routes
A server route is never prerendered, so a dynamic one needs no entries(). Its load() gets the visitor's request, for cookies, headers or query parameters.
// src/pages/account/[id].load.ts
export async function load({ params, request }) {
const session = await getSession(request.headers.get('cookie'))
return { account: await findAccount(params.id, session) }
}vite build writes static routes to dist/client and leaves server routes to the handler in dist/server/index.mjs, a fetch(Request) function. vite preview serves both, and clarusjs explain shows each route's mode.
Deploying server routes
On Netlify, add adapter: 'netlify'. The build then writes a Netlify Function that runs the same handler for the server routes only; static routes stay files and are served first.
clarusjs({
routes: { '/account/*': 'server' },
adapter: 'netlify',
})Anywhere else, serve dist/client as static files and send the server routes to dist/server/index.mjs: its default export has fetch(request), and isServerPath(pathname) says which requests are its own.