+page.js, +page.server.js, +layout.js, or +layout.server.js.
Child layouts and pages override values set in parent layouts, allowing you to configure different behaviors for different parts of your app.
prerender
It’s likely that at least some routes of your app can be represented as a simple HTML file generated at build time. These routes can be prerendered.Prerendering everything
You can setexport const prerender = true in your root +layout.js or +layout.server.js and prerender everything except pages that are explicitly marked as not prerenderable:
Auto mode
Routes withprerender = true will be excluded from manifests used for dynamic SSR. In some cases you might want to prerender a route but also include it in the manifest:
How prerendering works
The prerenderer will start at the root of your app and generate files for any prerenderable pages or+server.js routes it finds:
You can specify which pages should be accessed by the prerenderer using
config.kit.prerender.entries, or by exporting an entries function from a dynamic route.When not to prerender
The basic rule is: for a page to be prerenderable, any two users hitting it directly must get the same content from the server. Pages that cannot be prerendered:Pages with actions
Pages with actions
Pages with form actions cannot be prerendered, because a server must be able to handle the action
POST requests.Pages using url.searchParams
Pages using url.searchParams
Accessing
url.searchParams during prerendering is forbidden. If you need to use it, ensure you are only doing so in the browser (for example in onMount).Route conflicts
Because prerendering writes to the filesystem, it isn’t possible to have two endpoints that would cause a directory and a file to have the same name:entries
SvelteKit will discover pages to prerender automatically by starting at entry points and crawling them. By default, all your non-dynamic routes are considered entry points:entries function:
entries can be an async function, allowing you to retrieve a list of posts from a CMS or database.ssr
Normally, SvelteKit renders your page on the server before sending that HTML to the client where it’s hydrated. If you setssr to false, it renders an empty ‘shell’ page instead:
Turning your app into an SPA
Turning your app into an SPA
If you add
export const ssr = false to your root +layout.js, your entire app will only be rendered on the client — which essentially means you turn your app into an SPA.You should not do this if your goal is to build a statically generated site.csr
Ordinarily, SvelteKit hydrates your server-rendered HTML into an interactive client-side-rendered page. Some pages don’t require JavaScript at all:No JavaScript
The webpage works with HTML and CSS only
No scripts
<script> tags inside components are removedNo progressive enhancement
<form> elements cannot be progressively enhancedBrowser navigation
Links are handled by the browser with full-page navigation
trailingSlash
By default, SvelteKit will remove trailing slashes from URLs — if you visit/about/, it will respond with a redirect to /about.
You can change this behavior with the trailingSlash option:
- never (default)
- always
- ignore
/about/ redirects to /aboutconfig
With the concept of adapters, SvelteKit is able to run on a variety of platforms. Each of these might have specific configuration:config objects are merged at the top level (but not deeper levels):
Consult the documentation of your adapter for specific configuration options and type definitions.
Controlling page behavior
You can mix and match these options in different areas of your app:Marketing pages
Prerender for maximum speed
Dynamic pages
Server-render for SEO and accessibility
Admin section
Client-only rendering for SPA behavior