Intro to SPAs Concepts

Learning objective: By the end of this lesson, students will be able to discuss the difference between traditional web applications and single-page applications.

What is a single-page application?

In the past, all web apps were built as MPAs or multiple-page applications. MPAs send a brand new HTML page each time a user navigates around the app. For example, when a user clicks a link or submits a form, the server responds with a new HTML page for the browser to display to the user. The old HTML page is discarded.

Traditional web app

Single-page applications, or SPAs, are a different approach to building web applications.

SPAs still have links and forms, but when users interact with them, the back-end server replies with raw data (often in JSON format) or only the relevant HTML that needs to change. The old HTML page is retained, and changes to that page are made dynamically. All the updates are performed on the client side.

This means that the user can navigate to different parts of the application without the need to load a new page from the server.

Single-page app

Why single-page applications?

Downloads of React and Angular through time on npm

SPAs have become increasingly popular in recent years. This is reflected in the chart above, which shows downloads of Angular and React - which are widely used to build SPAs. Several factors have driven this evolution:

Real-world SPAs

SPAs are used in many popular websites and applications. Some examples of widely used SPAs include:

These examples demonstrate the wide range of applications that can benefit from using SPAs. These sites use SPAs to enhance the user experience by dynamically updating content within a single web page, eliminating the need for full-page reloads and providing a smoother, more responsive interaction with the application. This architecture aims to create a more app-like feel, improving efficiency and reducing latency in web applications.