The purpose of SPA (Single Page Application) is to make applications usable on nearly every device.
Nowadays, every device (desktop, laptop or mobile) running Windows, Linux, Android or IOS, includes a browser for the user to surf the web. When deploying modern business applications, wouldn’t it be a good idea to use this browser as the client? Instead of having to deploy fat client softwares on each user’s device? Taking into account the diversity in terms of hardware platforms and operating systems to support as well as other security considerations? Obviously, the answer is “YES”. Furthermore, this is particularly true for SaaS applications which must work on as many platforms as possible.
But, from an end user experience standpoint, surfing the web or using a business application are two completely different experiences.
- Surfing the web implies going from one web page to another, one content to another, where the user can feel consecutive full pages refreshes without getting frustrated.
- Using a business application though requires much more fluidity and fast interactivity experience. Typically in a traditional business application, the user’s interactions do not imply a complete application page refresh. The user feels it stays within one application environment.
Well, when you go to your favorite social network like Facebook, Twitter or LinkedIn, when you use business applications like Google Docs, Slack or Trello from your browser, or when you go to Netflix, AirBnB, Pinterest or Paypal, you already feel that you are using a real application, not surfing the web. How is it possible since you are using your browser?
The answer is “Single Page Application”!
How does SPA work?
A Single Page Application (SPA) is a web application that consists of a single HTML page. Instead of refreshing the whole page after each user interaction, as it is the case for traditional Multiple Page Application (MPA), only the data that must be updated triggers a partial refresh.
As an example, when you browse your Google emails, you do not notice significant changes during navigation. The sidebar and header remain untouched as you go through your inbox.
And this is the key to give the user the perception he/she is using a business application. The user stays within this fluid and highly interactive interface.
MPA – basic concept
Both SPA and MPA are based on the HTTP protocol.
In a traditional client/server MPA architecture, each click of a user triggers an HTTP request to the server. The result of this new request is a full page refresh, even if some of the content remains the same:[/vc_column_text][vc_single_image media=”3410″ media_width_percent=”100″][vc_column_text]
On the other hand, the core of a SPA is based on Ajax, a set of development techniques that enables the client to send and retrieve data from the server asynchronously (in the background) without interfering with the display and behavior of the web page. Ajax allows web pages and, by extension, web applications, to change content dynamically without the need to reload the entire page.
Advantages of SPA
Improved enduser experience and performance
As you can imagine, the first key advantage of an SPA when compared to an MPA is its ability to respond quickly to any user action.
Indeed, to execute a user’s request, an SPA loads a small JSON file instead of a new complete web page. Even by using techniques such as caching and lazy loading, MPAs are slower to get new data from a server than SPAs are. Furthermore, the fact that the page doesn’t need to reload makes workflows that involve multiple screens more streamlined in SPAs than in regular web applications.
The second advantage of SPA is again related to performance.
Even if new standards like 5G aim at delivering high speed bandwidth, using poor internet connections remains one of the major problems in guaranteeing good user experience.
Easier development process
Performance is not the only benefit of using SPAs.
The development process is also an important aspect to take into consideration.
By design, an SPA decouples the back-end services from the front-end display. It allows back-end and front-end designers to develop their own environment without having to worry about complex integrations that would require specific care. And they can freely use their preferred development languages and frameworks.
This clear separation of back- and front-ends also greatly simplifies the application evolution/modification that would inevitably occur during the whole application lifecycle.
Often, the back-end infrastructure remains unchanged, while the front-end evolves to align to constantly changing user experience requirements.
Ready for mobile
Finally, you can use the same SPA back-end to create a mobile application which is identical to the web application. It does not require much adaptation since the SPA is already designed as an application, not a website.
Disadvantage of using SPA
Adopting the SPA architecture in your web application development brings also some challenges.
First, you have to design your application carefully, taking into consideration potential future changes. Indeed, in regular web applications, the delivered services/functionalities are spread across multiple pages. It is quite easy to modify one page when required, without impacting any other. This is not the case with SPAs. Any change can widely affect components used throughout the application.
Another aspect not to forget is the load you put on the client, which can lead to memory leaks.
Last but not least, optimizing SEO for SPA stays a challenge.
Seeing that the users’ interactions do not trigger new URLs, it is hard to optimize SPA for search engines.
The Web Vitals that Google looks at to compute the SEO score are still mainly based on web pages loading and first interaction performances.
Chrome proposes some best practices for optimizing SEO in an SPA context.
Monitoring SPA performance through RUM: the visibility challenge
All subsequent Ajax calls triggered by the user must be monitored separately and must be associated with the SPA in order to provide an overall relevant SPA performance analysis.
So, as a summary, monitoring Ajax calls process (errors) and performances becomes much more important!
Despite some challenges mentioned above, adopting the SPA architecture seems to be the way to go to cover some of the major requirements delivering business applications today implies, which are:
- Delivering a fluid and smooth user experience
- Quick development process
- Agile design to quickly align to new user requirements
- Support any device, any operating system
- Guarantee good user experience in slow network conditions
This architecture is particularly suitable for SaaS applications.
On the other hand, monitoring performance of such applications is a challenging task because the SPA architecture pushes a lot of the application logic at the edge. Monitoring SPA performance does not only require to monitor the client devices performance, but also all API calls performed to back-end services (which can be yours or be hosted by third-parties and may involve other types of communications like DNS resolution and connections to CDNs). In other words, monitoring such an environment requires to get full visibility of enduser devices (device types, OS, browser, …) endusers location and network connectivity performance, API calls (identification of requested third-party services, the related performances as well as completion status).
If you would like to learn about to monitor Single Page Applications, please read this article.