Page options let you choose how your Svelte app loads and shows pages. This helps make your app faster and work better for users.
Page options (SSR, CSR, prerender) in Svelte
export const ssr = true | false; export const csr = true | false; export const prerender = true | false;
Set ssr to true to enable server-side rendering.
Set csr to true to enable client-side rendering.
export const ssr = true; export const csr = true; export const prerender = false;
export const ssr = false; export const csr = true; export const prerender = false;
export const ssr = true; export const csr = false; export const prerender = true;
This Svelte page uses both server-side and client-side rendering. The page content is sent from the server, and the button works in the browser to update the count.
<script> export const ssr = true; export const csr = true; export const prerender = false; let count = 0; function increment() { count += 1; } </script> <h1>Counter</h1> <p>Count: {count}</p> <button on:click={increment} aria-label="Increment counter">Increment</button>
If you set ssr to false, the page will not render on the server and will show a blank page until JavaScript runs.
Prerendering creates static HTML files at build time, which is great for pages that do not change often.
Combining SSR and CSR lets you have fast initial load and interactive pages.
Page options control how and when pages render in Svelte.
SSR sends ready HTML from the server for faster load.
CSR renders pages in the browser after loading JavaScript.
Prerender builds static pages ahead of time for fast delivery.
Practice
Solution
Step 1: Understand SSR concept
SSR means the server prepares the full HTML before sending it to the browser.Step 2: Compare with other options
CSR waits for JavaScript to render, prerender builds static pages ahead, and disabling JavaScript is unrelated.Final Answer:
It sends fully rendered HTML from the server to the browser. -> Option AQuick Check:
SSR = server sends ready HTML [OK]
- Confusing SSR with CSR
- Thinking prerender is the same as SSR
- Believing SSR disables JavaScript
Solution
Step 1: Recall syntax to disable SSR
In Svelte, settingexport const ssr = false;disables server-side rendering.Step 2: Check other options
prerendercontrols static generation,csris not a valid option, andssr = trueenables SSR.Final Answer:
export const ssr = false; -> Option CQuick Check:
Disable SSR with ssr = false [OK]
- Using 'prerender = false' to disable SSR
- Trying to set 'csr = true' which is invalid
- Confusing enabling and disabling SSR
export const prerender = true; export const ssr = false;
What will happen when this page is built and served?
Solution
Step 1: Analyze prerender and ssr flags
Settingprerender = truemeans the page is built as a static HTML file ahead of time. Settingssr = falsedisables server-side rendering on requests.Step 2: Understand combined effect
The page is generated once at build time (prerendered) and then served as static HTML. Since SSR is off, no server rendering happens on requests; rendering happens on the client.Final Answer:
The page is statically generated at build time and rendered only on the client. -> Option AQuick Check:
prerender true + ssr false = static build + client render [OK]
- Thinking SSR still runs on requests
- Assuming no rendering happens causing error
- Confusing prerender with SSR
export const ssr = false; export const prerender = false;
What is the problem with this setup?
Solution
Step 1: Understand the effect of both flags false
Settingssr = falsedisables server-side rendering, andprerender = falsedisables static generation.Step 2: Identify the consequence
Without SSR or prerender, the page has no prebuilt HTML and relies on client-side rendering only, causing a blank page until JavaScript runs.Final Answer:
The page will not prerender and also disables SSR, so it won't generate HTML before client loads. -> Option BQuick Check:
ssr false + prerender false = no prebuilt HTML [OK]
- Assuming prerender happens automatically
- Thinking this causes syntax error
- Believing SSR still runs when false
- Is prerendered as static HTML for fast loading
- Uses SSR only if the user is logged in
- Otherwise, renders on the client
Which setup best achieves this behavior?
Solution
Step 1: Understand prerender and SSR roles
Prerender true builds static HTML at build time. SSR true enables server rendering on requests.Step 2: Match requirements
To prerender for fast loading and also use SSR conditionally (like checking login), you need both prerender and SSR enabled. Server hooks can check login and decide rendering.Step 3: Evaluate other options
export const prerender = true; export const ssr = false; // Use client-side code to check login and fetch data disables SSR, so no server rendering on login. export const prerender = false; export const ssr = true; // Server renders always regardless of login disables prerender, losing static HTML. export const prerender = false; export const ssr = false; // Fully client-side rendering only disables both, no server or static rendering.Final Answer:
export const prerender = true; export const ssr = true; // Use server hooks to check login and render accordingly -> Option DQuick Check:
Prerender + SSR true for static + conditional server render [OK]
- Disabling SSR when conditional server render is needed
- Disabling prerender losing static HTML benefits
- Assuming client code can replace server login checks
Ready to prove it?
Pass the test and this pattern moves unknown
