What if you could make every page load instantly without extra work?
Why Page options (SSR, CSR, prerender) in Svelte? - Purpose & Use Cases
Imagine building a website where every time a user visits a page, your server has to create the entire page from scratch, or the browser has to build it all alone without any help.
Doing everything on the server can slow down responses and overload your server. Doing everything in the browser can make pages load slowly and hurt search engine rankings. Managing these manually is confusing and error-prone.
Svelte lets you choose how each page is made: on the server (SSR), in the browser (CSR), or ahead of time (prerender). This makes your site faster, easier to build, and better for users and search engines.
fetch data on every request and build HTML manually on serverexport const prerender = true; // build page once at deploy time
export const ssr = false; // build page in browser onlyYou can create fast, user-friendly websites that load quickly and work well everywhere by picking the best way to build each page.
A blog site can prerender all posts for instant loading, while a dashboard page uses SSR to show fresh data, and a settings page uses CSR for smooth user interactions.
Manual page building is slow and complex.
Svelte's page options let you pick the best rendering method.
This improves speed, user experience, and SEO.
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
