How to use static generation with SPA and SSR
Build public pages ahead of time and load account data after sign-in
Use static site generation for public pages whose content can wait until the next release. Use a client-rendered single-page application for signed-in screens that load private, changing data. Use server-side rendering when fresh or personalized HTML must appear in the first response.
These models can live in one product. A public site can use prebuilt HTML while an authenticated area uses a client-rendered app.
Separate rendering from navigation
Rendering means turning content and data into HTML or a visible interface. A route is a URL path that identifies a page or app screen. An app shell is the HTML document that loads an app's JavaScript. Client state is information kept while someone uses the app, such as filters or unfinished form values. A web application programming interface (API) lets the app request data or submit changes to a server.
Static site generation (SSG) creates HTML during a build, before a visitor requests a page. Server-side rendering (SSR) creates HTML on a server when a request arrives. Client-side rendering (CSR) creates the interface in the browser with JavaScript.
Single-page application (SPA) describes navigation. An SPA updates the current document when a user moves to another screen. A multi-page application (MPA) requests a new HTML document for each navigation. SSG, SSR, and CSR describe when and where the page content is rendered. SPA and MPA describe what happens after navigation, so an SSG site can use SPA-style navigation after its first page loads.
When JavaScript attaches behavior to existing HTML, the process is called hydration. For example, VitePress sends prebuilt HTML on the first visit and then uses Vue for navigation inside the site. That is SSG for the initial response with SPA-style navigation afterward. VitePress explains this rendering model.
Choose the model from the page's job
| Model | Use it when | Main trade-off |
|---|---|---|
| SSG | The page is public and its content can be a build-time snapshot, such as marketing pages, documentation, or a public catalog. | A content change needs a rebuild and a new release before the generated HTML changes. |
| CSR SPA | A signed-in user moves through several screens, and the app must keep client state while it loads current data. | The first useful view depends on JavaScript and often an API request. Direct app URLs need a fallback to the app shell. |
| Request-time SSR | Fresh or request-specific data must appear in the first HTML response. | Each request depends on a renderer and its data sources. Personalized output also needs deliberate caching. |
| MPA | Separate documents and normal links are enough, with little shared browser state. | Each navigation loads another document. Store information that must survive navigation in cookies, server storage, or another external store. |
These choices can be combined. For example, use SSG for a public product page, then link to a CSR SPA for account actions. Use SSR for a page that must include a current account summary before the browser runs application JavaScript.
Refresh individual pages or add interactive widgets
Incremental static regeneration (ISR) updates selected static pages without rebuilding every page. A platform serves a cached page, marks it stale according to its rules, and generates a newer copy for later requests. ISR needs runtime and cache support. A plain static file host cannot regenerate a file after deployment.
Client islands keep most of a page as static HTML and hydrate only interactive widgets, such as a calculator or carousel. This limits JavaScript on mostly static pages. It adds coordination when several widgets need shared state. Astro describes the islands model.
Build a public site with a signed-in app
Use this sequence when a product has public content and private workflows.
- Classify the data. Put only public data into generated pages. Keep account, wallet, and other private data out of build output.
- Generate known public routes. During the build, load the public content and create one HTML file for each route. Store shared JavaScript, styles, and images as shared assets. Before publishing, verify that each linked public URL has a generated page.
- Publish the generated files. A static host can serve the HTML, JavaScript, styles, and images. Static hosting describes delivery. It does not guarantee pre-rendered HTML, client-side behavior, or offline support.
- Route app URLs deliberately. If the signed-in app uses an example path such as
/app/, configure the host to return that app's HTML shell for valid nested paths under/app/. Serve existing public HTML for public routes. Return a 404 for missing public URLs. Do not apply the app fallback to every path. - Fetch private data in the app. After the browser loads the shell, the app restores the session and requests current data from authenticated APIs. The server must enforce access to that data. Client-side route checks improve the interface but do not replace server authorization.
- Choose how public updates arrive. Rebuild and publish when public content changes. A new source document or public record is not visible in generated HTML until a successful build publishes the new files. If updated data can appear after the page loads, fetch the latest public data in the browser. If fresh data belongs in the first HTML response, use SSR. If some cache staleness is acceptable, use ISR on a platform that supports it.
Check the result before release
Use a browser and the built files to check the generated pages and app routes.
- View the initial response for a public route. Confirm that its meaningful content is present before JavaScript runs.
- Open a nested app URL directly, then refresh it. Confirm that the app shell loads and the client router opens the correct screen.
- Open a missing public URL. Confirm that the host returns the expected 404 instead of the app shell.
- Change a public content item. Confirm that the expected rebuild, regeneration, or browser request makes the change visible.
- Open a signed-in screen with an expired or missing session. Confirm that private data is not returned by the API.
For a broader overview, read Rendering on the Web, VitePress rendering and navigation, Next.js ISR, and Astro islands.