Basic Svelte
Introduction
Bindings
Advanced Svelte
Advanced reactivity
Motion
Advanced bindings
Advanced transitions
Context API
Special elements
<script module>
Next steps
Basic SvelteKit
Introduction
Routing
Loading data
Headers and cookies
Shared modules
API routes
$app/state
Errors and redirects
Advanced SvelteKit
Page options
Link options
Advanced routing
Advanced loading
Environment variables
Conclusion
Server-side rendering (SSR) is the process of generating HTML on the server, and is what SvelteKit does by default. It’s important for performance and resilience, and is very beneficial for search engine optimization (SEO) — while some search engines can index content that is rendered in the browser with JavaScript, it happens less frequently and reliably.
That said, some components can’t be rendered on the server, perhaps because they expect to be able to access browser globals like window
immediately. If you can, you should change those components so that they can render on the server, but if you can’t then you can disable SSR:
export const ssr = false;
Setting
ssr
tofalse
inside your root+layout.server.js
effectively turns your entire app into a single-page app (SPA).
<h1>{window.innerWidth}x{window.innerHeight}</h1>