On my daily job I work on a typical Rails monolith app that uses rail for the API and business logic layer, and serves a SPA built in React.
The more my team and I work on the SPA side, the more I have the feeling that we are only really using the dynamic content loading and routing parts of a SPA, and the team that originally built this app could have gotten away with a much simple approach of using Rails views with sprinkles of React for the niceties it provides, like component state management, styled components, component libraries and so on.
I was first introduced to programming through JavaScript, and not very long after my initial introduction, I picked up React, and most online tutorials focused on building SPAs, so I had a hammer and everything looked like a nail. These days I am very reluctant to build a single page application for my own projects, and tend to only build a SPA when I want a completely decoupled API, but that is rarely the case, as the added complexity almost never adds enough benefits to justify it.
What do you guys think? Are we as an industry overusing SPAs, or are there legitimate reasons to always rebuild the browser's apis inside our javascript applications?
Top comments (2)
A thing that is hard to replicate without SPA is
Is there a meaning to <Link> in Gatsby.js, and is there something analogous for other SSG?
Pacharapol Withayasakpunt ・ Mar 15 ・ 1 min read
Otherwise, to me yet, SPA is just analogous to some template engine, like EJS or Jinja2.
I agree, there isn't quite anything like that outside of a spa. You can get something close with websockets and ajax, but you sort of need a server to do that. For static assets, you're pretty much stuck with loading a whole new page when you click on a link. I wonder how much of a benefit one truly gets from being able to override the default browser api for navigation though. From a performance point of view, my experience has been that static assets are much faster to load than a page with the weight of a framework.
Perhaps a decent solution for your problem is using something like Vue in the same way people used to use JQuery, for that extra bit of dynamic content on your, otherwise, static pages.
That is not to say that there's absolutely no value in SPAs, though. If one is trying to have the same code for their mobile apps and web app, that certainly makes sense.