SPA

On this page 7

An SPA (single-page application) is a web application that loads a single HTML document once and then updates the interface with JavaScript, fetching data in the background instead of requesting a new page from the server for every navigation. URL changes, view transitions and state are handled in the browser by a client-side router and an application framework.

Among web applications, the SPA model became dominant in the 2010s with frameworks such as Angular, React and Vue, because it delivers app-like interactivity after the first load. It also shifts substantial work to the client, which brings costs in initial load time, search visibility and accessibility that must be managed deliberately.

How an SPA works

An SPA works by serving a minimal HTML shell plus one or more JavaScript bundles; the bundle builds the interface in the browser, a technique known as client-side rendering. After that first load, every navigation is intercepted by the router, which updates the URL with the History API, renders the matching view and requests only the data it needs, usually as JSON from an API.

The table lists the components that nearly every SPA architecture contains.

ComponentResponsibilityTypical implementation
Application shellStatic HTML and the root mount pointOne index.html served for all routes
Client-side routerMaps URLs to views without reloadingHistory API with pushState and popstate
View layerRenders components and updates the DOMReact, Vue, Angular, Svelte
State managementKeeps data consistent across viewsComponent state, stores, query caches
Data layerExchanges data with the serverREST or GraphQL calls through the Fetch API
Build toolingBundles, splits and minifies codeVite, webpack, esbuild
Core components of a single-page application

Because the server returns the same shell for every path, the web server must be configured with a fallback route that answers deep links such as /orders/42 with index.html; otherwise a page refresh produces a 404 error.

SPA compared with other rendering models

The SPA is one point on a spectrum of rendering strategies, and the main alternative is the MPA (multi-page application), in which the server returns a complete HTML document for each URL. Modern frameworks increasingly blend these models through SSR, SSG and hydration.

ModelWhere HTML is producedNavigationMain trade-off
SPA with client-side renderingIn the browserInstant after first loadSlow first render, JavaScript-dependent
MPAOn the server for every requestFull page loadSimple and robust, less fluid
SSR with hydrationOn the server, then activated in the browserSPA-like after hydrationFast first paint, hydration cost
SSGAt build timeStatic pages, optionally SPA-likeVery fast, content must be prebuilt
PWAAny of the aboveCan work offlineAdds a service worker and manifest
SPA and related architectures

A PWA is not an alternative to an SPA but a set of capabilities layered on top; many PWAs are SPAs with a service worker that caches the shell for offline and repeat visits. Likewise, frameworks such as Next.js or Nuxt render the first view on the server and then behave as an SPA, an approach often called a hybrid or universal application.

Strengths and costs of the SPA model

The SPA model trades a heavier first load for faster subsequent interactions, so its value depends on how long users stay and how much they interact. Long working sessions favor it; short visits from search engines usually do not.

AspectBenefitCost
Navigation speedNo full reload; only data travelsFirst load must download and run the bundle
User experienceSmooth transitions, preserved stateBack button, focus and scroll must be reimplemented
Server loadServer returns JSON, not HTMLClient devices carry the rendering work
Team structureClear split between front end and APITwo deployable systems to version and secure
Search visibilityIndexable if rendered correctlyCrawlers may see an empty shell
Benefits and costs of single-page applications

Performance risk concentrates on mid-range mobile devices, where parsing and executing 500 KB or more of JavaScript can take several seconds. This shows up as poor LCP and, when large updates block the main thread, poor INP.

When to choose an SPA

An SPA is the right choice when the application is highly interactive, used in long sessions and largely behind a login, where search indexing and first-visit speed matter less than fluid work. The decision table summarizes typical cases.

Use caseRecommended approachReason
Internal dashboard or admin toolSPALong sessions, no SEO requirement
Online editor or design toolSPAComplex client state and instant feedback
News or blog siteMPA or SSGShort visits, search traffic, fast first paint
E-commerce storefrontSSR with hydrationNeeds both SEO and interactivity
Field app with poor connectivitySPA as a PWACached shell works offline
Choosing an architecture by use case

Common pitfalls in single-page applications

  • Ignoring accessibility on route changes. Without a full reload, screen readers do not announce the new page; the application must move focus and update the document title on every navigation.
  • Shipping one monolithic bundle. Route-based code splitting and lazy loading of rarely used views keep the first download small.
  • Breaking browser conventions such as the back button, scroll restoration, opening links in new tabs and deep linking.
  • Memory leaks from listeners, timers and subscriptions that survive after a view is removed, which accumulate in sessions lasting hours.
  • Storing tokens in localStorage, which exposes them to any injected script; HttpOnly cookies with CSRF protection are the safer default.

Analytics also need adjustment: page-view tracking based on full loads undercounts SPA navigation unless the router reports virtual page views.

A non-technical view

An SPA is a website that behaves like an app. A classic website sends a fresh page every time a visitor clicks a link. An SPA loads once and then changes only the parts of the screen that need to change.

Imagine a stage play. A classic site lowers the curtain and builds a new set for every scene. An SPA keeps the stage and simply moves the props. That makes later scenes quick, but the first scene takes longer to prepare. This is why SPAs suit tools people use for hours, such as email or project boards.

A concrete example

A logistics company builds a dispatch console that coordinators keep open for an entire eight-hour shift. They switch constantly between a map, a list of drivers and order details. The team builds it as an SPA with a client-side router and a query cache, so moving between views takes under 100 ms and the map never reloads.

The first load downloads about 400 KB of compressed JavaScript, which takes around three seconds on the older office laptops. The team accepts this because it happens once per shift. To keep it in check, they split the reporting module into a separate bundle that loads only when a manager opens it.

The public tracking page for customers is built differently, as a server-rendered page that appears quickly from a text-message link. The two choices reflect the same principle: the SPA model pays off where sessions are long.