Should you write a Single Page App?
Quite simply, my personal answer to this is Yes.
I recently read an article on here against SPAs, for various reasons. Things like how you can’t link to pages, how the back and forward buttons don’t work correctly, and so on. And then going on to point out all the benefits of writing a traditional HTML based web site. And I’m not going to dispute that at all.
However, there are a surprising set of advantages the the SPA gives you as well, and you can easily avoid the disadvantages.
Avoiding the disadvantages first. Using something like — for my personal preference — create-react-app and React Router we get:
- URL routing
- Fully functional back and forward buttons
- Ability to refresh the browser — including if it closes and reopens
- Fully functional deep linking to pages
And it’s really simple to implement. In some ways, it’s actually harder to not get those features. You can also trivially add on things like i18n to give a much better end user experience.
And it gets better still. An SPA essentially mandates an API onto your backend — in order to read and write data. This API can not only be reused by other interfaces — e.g. if you decide to do a native Android/iOS app — but it’s also significantly easier to test. And this makes it more reliable and more stable.
And you also get to write tests for all of your UI components as well. Actual end-to-end UI tests are very brittle. But doing unit tests of the components and end-to-end tests of your API gives you most of the same coverage in a significantly easier, and more stable manner.
And this really shouldn’t be underestimated. How often do you get frustrated at websites that just don’t quite work right? That have odd bugs that you really can’t believe got through QA. Unfortunately, a lot of small sites just can’t afford good QA. But automation of that can be a huge win, and is so much easier in the SPA world.
So, when considering if you should write an SPA or a traditional web site, take everything into account. But make sure you do it right and use the right tools for the job, in order to make the best that you can.