On a classic website every navigation is a new request to the server and a new HTML page. In an SPA there are no such navigations: the browser loads the application once, the code then redraws the content itself, and it contacts the server only for data, usually JSON.
How it works
The first request returns almost empty HTML: a shell of markup and a link to JavaScript. The browser downloads and runs the code, which builds the interface in the DOM and asks the server for data. From then on the application lives on the client: JavaScript handles clicks, fetch retrieves new data, and the page is never fully reloaded.
const list = await fetch("/api/tasks").then((r) => r.json());document.querySelector("#app").innerHTML = render(list); // redrew the list without a reloadRouting in the browser
The address changes without navigating to a new document. The old way stores the route after #: the URL fragment is not sent to the server, so changing it does not load a page. The modern way is the History API: pushState adds an entry to the browser history and changes the address bar without reloading the document. React Router, Vue Router and Angular routers use exactly this.
history.pushState({ page: "task" }, "", "/tasks/42");// the address bar shows /tasks/42, the document is the same; when “Back” is pressed// the browser fires a popstate event and the router renders the previous viewThe History API has a restriction: the new address must be in the same origin as the current document. It also has a cost: the server gives a full response only for the application’s entry address and does not know the other routes, so opening a link in a new tab or refreshing the page requires server configuration: serving the same HTML shell for any application route.
SEO drawbacks
A search crawler first scans the HTML. In an SPA the first HTML is almost empty, so the crawler puts the page in a separate rendering queue and runs the JavaScript in a headless browser on its own resources; the queue takes from a few seconds to longer. The second problem is server responses: an SPA answers every address with the same shell and a 200 status, so a non-existent page looks real to the crawler, producing a soft 404. There are also meta tags: all “pages” share one title and description unless the code replaces them on the client.
- The first HTML is almost empty: content appears only after JavaScript runs, and rendering in the crawler’s queue can take more than a few seconds.
- The server answers 200 for any route, so non-existent addresses look like a soft 404.
- Links must be real
<a href>elements: navigation built on clicks on adivdoes not let the crawler find pages. - Metadata is shared across the whole application unless the code replaces
titleanddescriptionfor each route.
The remedy is to return HTML from the server: SSR or prerendering, which are built into Next.js and Nuxt. An SPA is best built as an application rather than a site: dashboards, editors and admin panels are interfaces behind a login, where content changes often and search traffic is not needed. Content sites and storefronts are usually built with SSR or static generation, so that HTML with the content arrives immediately, for people and crawlers alike.
Sources
the term is written from these pagesVerified 9 Nov