Pre-rendering means to render the HTML of pages at build-time (when running $ vike build).
Without pre-rendering, the HTML of a page is rendered at request-time (when the user goes to that page).
If you pre-render all your pages, you don't need a production server: your app consists only of a static assets (HTML, JS, CSS, images, ...) that can be deployed to a static host (GitHub Pages, Cloudflare Pages, Netlify, ...).
If you don't pre-render, you need a production server to dynamically render your pages' HTML at request-time. (Deploying a Node.js server to AWS, Cloudflare Workers, Vercel...)
Tools that pre-render pages are also known as "SSG" (Static-Site Generators).
Should I pre-render?
In a nutshell: pre-render your pages whenever you can.
Because pre-rendering removes the need for a production server and makes deployment very easy and very cheap (usually free). It's also significantly more performant as the HTML isn't re-generated on every HTTP request.
But pre-rendering cannot be used for websites with content that changes very frequently. For example Hacker News or Reddit: users are constantly creating new posts, which would require pre-rendering to run again each time — pre-rendering the entire website (millions of pages) every millisecond isn't possible.
In theory, it's possible to re-render only the subset of pages that are affected by new content, but it isn't practical (it has been tried before) and we recommend against this practice.
Technically, the bottom line is: how frequently does the HTML of your pages change? See:
Pre-rendering can be used for websites with content that changes only occasionally. For example, the content of https://vike.dev changes only when a maintainer updates the documentation — the entire website https://vike.dev can then be pre-rendered again every time there is change.
This website https://vike.dev uses pre-rendering and is deployed to GitHub Pages — a static host that is completely free, easy to use, and performant.
How to pre-render
To opt into pre-rendering:
// pages/+config.tsimport type { Config } from 'vike/types'export default { prerender: true} satisfies Config
Your pages' HTML are rendered when you run $ vike build and the generated HTML files are available at dist/client/.
For a page with a parameterized route (e.g. /movie/@movieId), you have to use the onBeforePrerenderStart() hook in order to provide the list of URLs that are to be pre-rendered. The onBeforePrerenderStart() hook can also be used to accelerate the pre-rendering process.
The only difference between SSG and SSR is when the HTML is rendered:
SSG: the HTML of the page is rendered at build-time (when calling $ vike build).
SSR: the HTML of the page is rendered at request-time (when the user goes to the page).
The client-side code of the page is always loaded and executed in the user's browser at request-time (regardless of SSG and SSR).
If you pre-render all your pages, there's no server — all "server-side code" runs at build-time. Calling it "server-side code" is technically a misnomer, but we keep the term for simplicity. One way to think about pre-rendering is that it essentially means "pre-rendered SSR (Server-Side Rendering)".
Essentially, and technically, SSG means SSR + pre-rendering:
// pages/+config.tsimport { Config } from 'vike/types'// SSGexport default { prerender: true, ssr: true // (optional: `ssr` is true by default)} satisfies Config
But when the user visits an SPA page, the browser still needs an HTML response to kick off client-side rendering. This HTML is just an empty shell (it doesn't contain the content of the page). If you want to avoid the need for a production server, you can pre-render this empty shell:
That's why the common practice is to set ssr: false together with prerender: true.
In a nutshell: the only difference is that the content of your SSG pages is included in the HTML, while the content of your SPA pages isn't.
Even though the content of SPA pages is missing, meta information (title, description, social image, ...) is still included in the pre-rendered HTML. See Guides > <head> tags > SPA.
Can I use SSG + SSR?
Yes, you can have SSR pages while others are SSG.
SSG is basically "pre-rendered SSR", see SSG vs SSR.