Let's assume that you have been developing the websites in the 'old' way. The end user opens it in the browser and navigate through it.
Aside graphical interface the whole page was downloaded from the server. Every click resulted in sending a bunch of files by the server. Moreover if the user has bad internet connection this exchange might cause seconds to load the page! This is how it have been working behind the scenes.
Wouldn't it be nice to involve the server only once to load the page and navigate through it ? This is where SPA comes in.
Wikipedia provides rather clear definition but let's take a closer look
,,A single-page application (SPA) is a web application or web site that interacts with the user by dynamically rewriting the current page rather than loading entire new pages from a server."
Let's dive deeper.
SPA loads all the bundled content for the first time when you make a request by typing i.e.
www.myAwesomeSPAWebsite.com in the browser.
You can see that after the initial response from the server later on it would send the
JSON data. Most of the
requests in the app are moved to the client side. Server is mostly responsible for authentication and connecting with database.
In popular SPA frameworks such as React, Vue, Angular, code of the website is split in components. In general when you navigate through the page, other components are rendered replacing the content instead of download it from the server and reloading the whole page.
Using the website is faster - Because everything is loaded by the first time the client can change the content on the page instantly. In other words our app works like the desktop application because it doesn't need to communicate with the server again to properly display the page.
Decreases the server load - SPA works different with the server at the communication level than the traditional page. To understand this better we can compare this process with building a house. Imagine that you(client) would have to carry bricks(data) one by one wasting your time(like in traditional websites) or you can just use the wheelbarrow(all of the data) and load all of them at once(using SPA). Now you have to transport them only once at the beginning. From now on you do not care that a bricklayer sends you to bring some bricks again. You (the server) can rest.
User experience (UX) - UX refers to any interaction a user has with a product or a service. The fact that you don't have to wait till the page reloads, gives you more pleasure of using it.
Less amount of transmitted data - I have mentioned that all the data is loaded at at once at the beginning. Moreover there are mechanisms that allows us to define which data should be loaded on the first request and which can be load later. It also increases the UX of the app.
Modern solutions - Thanks to use modern solutions the code of an app can be more minified. You are also able to use microservices. This gives you a possibility to divide your app into services that provide an API.
Developers pay more - SPA can be simply written in HTML, JS and CSS but sooner or later you will realize that you need to learn i.e. Webpack, Express, React/Vue/Angular and other accompanying solutions. This can be frustrating at the beginning but it is worth to learn them.
Should you use SPA for your future projects?
Well, as always you should consider every pros and cons to choose the best option. Maybe it is not worth to develop SPA, maybe the overall cost would be too much. There can be more subjective pros and cons depending on the developer preferences. However it is worth to keep track this rapidly developing SPA world.