10 ms·
Your arguments seem to be assuming a particularly bad implementation of a traditional backend. 1. A good server-generated-HTML backend will have no more state
by lolinder 5y ago
Your arguments seem to be assuming a particularly bad implementation of a traditional backend.
1. A good server-generated-HTML backend will have no more state than a good server-generated-JSON backend. The client state is all stored in the client either way, whether in JS variables, HTML tags, or the URL.
2. A good server-generated-HTML backend doesn't do significantly more work just because its output is in HTML instead of JSON. A bit of extra text generated isn't going to increase your CPU load in any meaningful way.
3. There are only fewer languages to deal with if you aren't in charge of writing backend code. If you're in charge of the backend code, you still have to pick a backend language for your JSON API.
I think you're assuming that the choice is "SPA" or "messy stateful monstrosity". It's perfectly possible to build a RESTful HTML-based API that is as clean and stateless as any JSON API. PHP's been starting each request with a clean slate for decades.
- gefhfffh 5y ago> a bit of extra text Doesn't really sound like an application, but a website. In a web app it can happen that you use it for an hour without the backend doing a single thing. > There are only fewer languages to deal with if you aren't in charge of writing backend code. You don't have to deal with them at the same time
- midrus 5y agoThere is no black or white here. 98% of every site is in between those things and you could consider them one way or the other. Is reddit a website or an application? is a backoffice dashboar a website or an application?. The problem with SPAs is not the technology or the architecture itself. The problem is everyone thinks, by your own definitions, they are building an "app" by default. I've already worked for several teams which struggle to get almost anything done and everything takes ages to ship because of the fanaticism of using React for everything. God, some didn't even know you could submit a form without building a json API endpoint.
- CRConrad 5y ago> Doesn't really sound like an application, but a website. Yeah, well, from the name of it, doesn't that sound like what the Web is for? I mean, we already have systems to run applications on; they're called operating systems. Not only SPAs but "web applications" as a whole are a mistake IMO.
- lolinder 5y ago> Doesn't really sound like an application, but a website. "text" here is as in "text/html", not as in "English-language copy". > In a web app it can happen that you use it for an hour without the backend doing a single thing. I would submit that this is an extremely rare case. The most involved web apps I interact with (say, Figma) are constantly syncing their state with the server. The simplest (say, TurboTax) save state as I move on to the next screen. If you do have a case where you can pull that off, then by all means use an SPA. But it's weird to say that something isn't a web app unless it can go long periods of time without server interaction.
- gefhfffh 5y agoI haven't said that something isn't an app, unless it can go long periods of time without server interactions. Generally, server interactions are arbitrary with SPAs, while SSR will happen all the time. Going only a few minutes without server interactions in an interactive app is a big leap compared to SSR. PS: I not only can pull that off, but I did. It's not too hard to think of apps like that. Consider e.g. Vscode
- lolinder 5y agoIf the app is VSCode or anything like it, that's a great candidate for an SPA and I agree wholeheartedly that you made the right choice.
- PeterisP 5y ago> Doesn't really sound like an application, but a website. That's probably the key thing - most companies building SPA's don't really need an application but a website. There are many interesting products that need to be applications because of the functionality they need, but for every one such product there's at least a dozen that does not.
- dzhiurgis 5y ago> isn't going to increase your CPU load in any meaningful way. yes but it would be soul crushing for a developer
- anonymoushn 5y agoWhy?
- dzhiurgis 5y agoI’m not experienced with best in class tooling (probably with worst) but seems very quick, easy and native to render html using js.
- CRConrad 5y ago> seems very quick, easy and native to render html using js. Seems even quicker, easier and "more native" to render HTML as, you know... HTML.
- rrrhys 5y ago> Your arguments seem to be assuming a particularly bad implementation of a traditional backend. These weekly SPA complaint threads always assume a particularly bad implementation of a SPA as well though.
- midrus 5y agoThe key here is that if we consider equivalent good and robust implementations, equivalent capable teams, same UX, etc of an SPA and a traditional full stack MVC application with a modern ajax tool such as livewire, hotwire, etc the latter takes a fraction of the time and cost to build and the result is far less complex and easier to maintain. I've worked in both kinds of environments, and unless you're building an offline first app, dogma, or Google maps...SPAs make absolutely no sense from the engineering point of view.
- midrus 5y ago*figma, not dogma. Autocorrect messed up and just noticed.
- deleted 5y ago[deleted]
- kristopolous 5y agoYou always have to fight with incompetency in any large codebase. Incompetency exists the most in whatever the first thing that coders learn is. I'm old enough to remember when that was c++, then it was java, php, ruby, jquery, now it's react. It's always a trade-off. You can build things in the "cheapest" language (whatever the first one currently is) but then you'll inevitably get the cheapest code That's really what this conversation is about in the long arc of coding Skills and people are a pyramid. The more competency you demand the harder the people are to find. We have this tendency to taint the tool by the users. Incidentally after a language or tool loses "first learned" status it generally slowly regains its prestige. We don't assume a c++ shop is a bunch of morons any more or that using php means you write nothing but garbage. One day vue/react/whatever will lose its first language status as well and I'll be here reading about something that might not have been invented yet being a trashy bad no good idea Ultimately the technical merits are mostly cover for a conjecture of economic efficiency. There's a reason why people aren't defending things like applications built with Go/wasm bridges - those people are expensive
- rtpg 5y agoMulti-page forms without some front end stuff ends up with the very clunky either "rerender previous form pages over and over again, except hidden", or "have some token to track partial form data", or "build up a DB to store a partially complete form". With some frontend work you can have a multi-page form just work, with the data stored in the client up until final submission, and only sending in partial checks ahead of time. This is qualitatively easier to handle, in my opinion. It also seems extremely uncontroversial that sending data for a single item is going to require less text generation than sending over that data + the entire page. These are all gradients, but people make absolute claims that don't hold up in these arguments.
- midrus 5y agoThe alternative to SPAs is not 90s pages reloads. Nowadays you have livewire, hotwire, unpoly, htmx and several other modern solutions.
- lolinder 5y agoI've built a multi-page form in an SSR app with a tiny dash of JavaScript. The form's children are divs. The Next button hides the current div and shows the next one. The final Submit button is just a regular submit. If you get into more than 3 pages, this isn't a great approach for various reasons, but you don't need to reach for a framework the instant you have a multi-page form.
- midrus 5y agoThe alternative to SPAs is not 90s pages reloads. Nowadays you have livewire, hotwire, unpoly, htmx and several other modern solutions.
- midrus 5y ago> "rerender previous form pages over and over again, except hidden" There are modern ways to do this, see Unpoly, HTMX, livewire, hotwire, etc. You're comparing with an outdated view of what an MVC application looks like. It's like to complain about SPAs because of backbone.js > "have some token to track partial form data" This is called "sessions", the token you refer to can be a cookie, which is done by default for free on any MVC framework. Doing this in any other way lead to either losing authentication on page reload or security vulnerabilities (storing a token in localstorage, etc). > "build up a DB to store a partially complete form" Again, you can store partial data in a session, for free. As it comes by default with any MVC framework. One of the key points here is that with any of the popular MVC frameworks you don't need to rebuild the wheel and the car from scratch as with SPA frameworks, most of these things come for free, specially anything related to forms. This is something we're not used to have in the SPA world and everyone has a different way to deal with it. > Multi-page forms without some front end stuff Nobody says there shouldn't be any frontend stuff, you still need it of course. If fields are static between steps you can just render every step and toggle between different set of fields using something like Alpine, no need to reload from the server. If fields are dynamic and need some kind of database lookup between steps, Unpoly or livewire/hotwire make this trivial. Please, let's stop comparing Next.js/React top modern SPAs to 20 year's ago struts MVC, it has not been like that since many years ago already.
- nfw2 5y agoMost SaaS developers aren't serving APIs to their clients, they are serving websites and web applications. Applications have state. In order to render and deliver the application, the server needs to have some concept of what that state is.
- onion2k 5y agoYour arguments seem to be assuming a particularly bad implementation of a traditional backend. Whenever someone says "this particular architecture is bad!" they're talking about a bad implementation of it. The point is whether or not you're more likely to succeed at making a good app with an SPA or a multi-page site. For pretty much all brochure-styles websites and many SaaS webapps you're more likely to achieve success (for every common understanding of success) by using a multi-page architecture because they're usually simpler to implement, they work the way browsers expect things to work, and you don't need to implement some hard things yourself. You can make a brilliant SPA website for any purpose, but often people try and fail. Saying "you shouldn't have used an SPA" is shorthand for "You didn't understand or implement an SPA well enough, and now your web thing is failing to serve users as well as it should, and using a multi-page architecture would have avoided the problems your website has now."