csr: true in a SvelteKit page?Consider a SvelteKit page configured with export const csr = true; and export const ssr = false;. What will the user see when they first load the page?
export const csr = true; export const ssr = false; <script> let count = 0; </script> <button on:click={() => count++} aria-label="Increment count">Count: {count}</button>
Think about what happens when server-side rendering is turned off but client-side rendering is on.
With ssr = false and csr = true, the server sends almost no HTML. The page is blank until the JavaScript loads and renders the component on the client. Then the button appears and is interactive.
Choose the correct way to disable server-side rendering and enable prerendering for a SvelteKit page.
Remember that ssr controls server rendering and prerender controls static generation.
To disable SSR, set ssr = false. To enable prerendering, set prerender = true. This combination disables server rendering but still generates static HTML at build time.
data when using prerender with a load function fetching static data?Given this SvelteKit page with prerender enabled and a load function returning static data, what will data.message be when the page renders?
export const prerender = true; export async function load() { return { message: 'Hello from prerender!' }; } <script> export let data; </script> <p>{data.message}</p>
Prerendering generates static HTML at build time including load data.
With prerender = true, the load function runs at build time. Its returned data is included in the static HTML. So the message appears immediately without waiting for JavaScript.
This page has export const prerender = true; but build fails with an error about fetch. What is the likely cause?
export const prerender = true; export async function load({ fetch }) { const res = await fetch('/api/data'); const data = await res.json(); return { data }; } <script> export let data; </script> <p>{JSON.stringify(data)}</p>
Think about what happens when prerender tries to fetch data from an API endpoint during build.
During prerender, the build process runs without a running server. Fetching from a relative API path like /api/data fails because the endpoint is not available. This causes the build error.
In SvelteKit, you want a page that is fully static: rendered at build time, no JavaScript sent to the browser, and no client-side interactivity. Which combination of options achieves this?
Consider what each option controls: prerendering, server rendering, and client rendering.
Setting prerender = true generates static HTML at build time. Setting csr = false disables client-side JavaScript. Keeping ssr = true allows server-side rendering at build time. This combination produces a fully static page with no client JS.