liveBook · Manning

Single-page application

As explained in Vanilla Web

A single-page application is a web application that updates its interface within one loaded document rather than performing full document loads for each view.

A single-page application (SPA) loads an entry document, then handles navigation in client-side code. A custom router selects views, and client-side code renders subsequent sections and data, optionally requesting data or partial code over HTTP. Moving between views does not require a new browser navigation that reloads the page context. section 2.1.4

Choose this navigation model for the application’s requirements, not as a default. A multi-page application serves different sections at different URLs through browser navigation. The approaches can coexist: a site can serve static sections as multiple pages while using an SPA for one part. section 2.1.4

Opening a route directly

Opening /products/42 sends an HTTP request to the server before the client router runs. For a route owned by an SPA shell, the server returns the entry HTML; once it loads, the router reads the URL and renders the matching view. Without that server behavior, client-side routing alone cannot handle the direct request. section 10.2

Configure the server fallback deliberately:

  • Return the SPA entry document for routes the client renders, but serve real files and API endpoints normally. section 10.2
  • Return a real 404 for routes that should not exist; do not hide them behind an empty shell. section 10.2
  • If deployed under a subpath, account for that prefix in both the server rewrite and client router. section 10.2
Figure 10.2 A link in a shell-based SPA starts on the server, the server delivers the shell (index html) and then the client router in JavaScript is responsible for rendering the view based on the URL.
ch10 F002 firtman

The request sequence shows why the server must deliver the shell before client-side routing can render a linked view. section 10.2

A pure SPA is not the only way to provide usable URLs. Server-side rendering returns route-specific HTML on request; static site generation produces it ahead of time. For public content where discoverability matters, those approaches or prerendering may be a better fit. section 10.2

How Vanilla Web covers it

How deep it goes
Explains the navigation model and server fallback behavior, without detailing a router implementation.
Examples
Uses a direct request to /products/42 and a deployment under /dashboard/ to expose routing configuration failures.
What it assumes
Assumes familiarity with browser navigation, URLs, servers, and client-side code; defines SPA navigation from the architectural decision.
What you can do after
Operate/configure it by rewriting app routes to the entry document while preserving files, API endpoints, and genuine 404 responses.
How it connects
Connects client-side routing with multi-page applications, server-side rendering, static site generation, HTTP requests, and server rewrites.

Also explained in

Compare how 6 books explain single-page application →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Vanilla Web. The section links point to the parts of the book it draws on.