What is an SPA?
In the early days of web development, it was fairly simple. A developer wrote a form using HTML that sent requests to a server, and based on the form content, redirected them to another page.
Why use an SPA?
What are the downsides of an SPA?
But a single page application has it's downsides:
Second, what seems like a page on an SPA is actually just one of a number of possible frames living in a single page, because of this SPA pages often don't have an address like a URL that is easy to share with others.
Third, keeping track of data on an SPA can be complicated. Developers have to come up with different patterns for handling the data changes and these can sometimes lead to confusion and bugs.
Fourth, adding to the complication, data still has to be processed and stored using a server. So by using an SPA you are not escaping writing code for a server (known as backend code.) The server is just configured to send data back to the page, rather than redirect to a new page. This creates two different codebases that have to be maintained.
Are there any alternatives to an SPA?
There are alternatives to using an SPA, they just aren't as popular and have their limits:
I've found use cases for all of these alternatives—especially when the functionality I need is very limited. As much as I dislike Single Page Application frameworks, and as much as I want to see some of these alternatives succeed, our team still reaches for them 90%.
So when should you use an SPA?
There are several cases where it just makes sense to use an SPA framework:
- If you know your app is going to need a native app (iPhone, Android) you should probably just use an SPA framework.
- If you want to run your web app as a native app on Mac, Linux or Windows using electron, an SPA framework will help you.
- If the app you are running is fairly complex (more than just a few forms and buttons) then you might want to consider an SPA framework.
Single Page Application frameworks offer a big leap forward in what developers can do with web technology. While they offer amazing functionality, that functionality comes with complexity and a loss of some of the the things web technology does right. Unfortunately, for many modern web apps, there is no good alternative.