Single Page Apps (SPAs) are quickly becoming the conventional wisdom for building rich web applications. I for one am a big fan of SPAs in general and a certain superheroic framework in particular.
The Case Against Single Page Apps
Probably the most comprehensive case against SPAs was made by Stefan Tilkov in his talk "Web Development: You're Doing it Wrong". In it, he explains why he considers SPAs to be problematic by contrasting them with applications written in a style he refers to as Resource Oriented Client Architecture (ROCA).
So, what is ROCA? Here's a quote from the ROCA Website describing it:
ROCA is an attempt to define a set of recommendations — independent of any particular framework, programming language, or tooling — that embodies the principles of what we consider to be good web application architecture. Its purpose is to serve as a reference, one that can be implemented as-is or be compared to other approaches to highlight diverging design decisions.
Though the quote above doesn't mention specific frameworks, Rails 4.0 (which is heavily influenced by a recent redesign of BaseCamp) is probably the most notable real-world implementation. Pjax is another popular framework which can be used to implement a ROCA-style app.
ROCA vs SPA
What then is the difference? There are a few, but the main one is the format those RESTful backends provide to the client. In SPAs, the data being sent to the browser is either JSON or XML. The responsibility of converting that data into a browser-compatible HTML view rests entirely on the client. In ROCA, the data being sent to the browser is HTML.
In fact, all of the reasons listed above are why ROCA supporters favor it over SPA. In their view, SPAs fundamentally break the web paradigm by essentially recreating desktop apps in the browser. On the other hand, ROCA apps fit nicely within the web paradigm by embracing HTML as the format for exchanging data between client and server.
My Two Cents
Generally speaking, I'm not a fan of reflexively using a technology or an approach irrespective of the problem being solved (with notable exceptions). From this perspective alone, I do agree that using SPAs for everything is not ideal.
Furthermore, a major reason why I like SPAs in the first place is that they force you into creating resource-oriented applications. ROCA does the same and further enforces web compatibility via adherence to HTML.
But What About Performance?
Since SPAs offload a lot of processing to the client, they're often thought to be more performant and scalable than server-heavy alternatives. The reality is a lot more nuanced.
Consider BaseCamp's heavy use of sub-component caching (i.e. "Russian doll" approach). BaseCamp individually caches every piece of content displayed on a given page. This cache is global and can therefore be reused between pages, users, apps, etc. What does this mean for performance? Even though all of this HTML is generated server-side, page rendering is ultra fast (100ms or less).
Now, BaseCamp's domain (project management), works well with this approach. There are many independent pieces of content, which can be combined, shared across pages and users, and so on.
Ok, so Desktop Apps on the Web Are Bad, Right?
Well, no. I do think that certain types of apps (games, image editors, word processors, possibly mail clients, etc), are well suited to the "desktop" metaphor. The really interesting question is how does one decide whether SPA or ROCA is the right option.
Without too much thinking about this (as is my custom), I would assume ROCA to be the default approach and use SPA if the app:
- doesn't require a server at all (ex. image editor)
- exposes many complex interactions on a large resource (ex. word processor)
Are there other areas where SPAs would work better?
You may also like:
Did you love / hate / were unmoved by this post?
Then show your support / disgust / indifference by following me on Twitter!