7 ms·
SPAs: theory versus practice
- leetrout 4y ago> Want to avoid re-rendering the whole page, when there’s only a small subset that actually needs to change? You can’t; it’s a “full page refresh.” This is where we a missing the middle ground in the debate. I do not consider a server rendered page that then uses HTMX (or "just" jQuery) to do partial refreshes or given areas of interactivity to be a SPA. So yes I can have my MPA and I can have partial content refresh and that does not require going all in on SPA frameworks.
- Graffur 4y agoYour point seems to be more of HTMX vs React rather than SPA vs MPA. With SPA frameworks you can deliver pages that can be accessed by the user (rather than just a single entry point). The difference becomes how the developer decides to build the application. Do they load all of the apps data on the first page load or do they retrieve it as the user browses around?
- josephscott 4y agoThis. Call it MPA Foundation, or something. With an MPA foundation there are plenty of opportunities to make easy improvements to performance and page experience, while still having all of the page features work without JavaScript. Not because there are tons of users running around with JS turned off, but because every page load is running without JS until the JS finishes executing successfully ( as noted by many others ).
- marcosdumay 4y agoWhat's up with partial refresh that developers want it so much? Usually the only gain is that you don't have to reload and re-parse all the javascript that is there for doing partial refreshes.
- jaredcwhite 4y agoExactly right! I find the SPA vs. MPA debate to be tedious, if not downright misleading, because it's perfectly possible build a web app that starts out as a basic MPA and then with (hmm, what's that term I'm looking for…wait for it…oh yeah!) *progressive enhancement*, you make it more and more SPA-like by loading in HTML fragments and making incremental DOM updates, updating the URL whenever possible to mirror backend state, etc. Heck, just with Turbo Drive alone, you can eliminate the "full-page reload" problem of MPAs with essentially zero (custom) JavaScript and it works great with static sites, full SSR frameworks, you name it. We desperately need better terminology around this stuff and the willingness to engage in nuance and see these it as a broad spectrum of various approaches you can mix 'n' match—sometimes all in the same project! Saying "oh this app's MPA, oh that app's SPA" will totally lead n00bs astray who aren't familiar with the production-level nuances involved.
- woojoo666 4y ago> I do not consider a server rendered page that then uses HTMX (or "just" jQuery) to do partial refreshes or given areas of interactivity to be a SPA. Why not? HTMX is itself a framework right? The distinction between SPA and MPA that the article gives (and that I agree with) is that MPA's delegate routing and page transitions to the browser. This naturally leads to less control (which makes the best case MPA worse than SPA), but also less complexity (which makes the average case MPA better than SPA)
- pier25 4y agoFantastic article and I totally agree with Nolan here: > I remain skeptical that we’ll get there, and even the best SPA would still have problems (complexity, performance on slow clients, etc.), but I can’t fault people for trying. In the best case scenario someday building an SPA will be closer to building a mobile or desktop app. But even with batteries included (native widgets etc) those types of projects are inherently more complex than building a series of self contained pages. Of course a great SPA is always going to be better than a great MPA, but the effort to get there is huge. I interact daily with SPAs made by corps with big budgets and they aren't able to get it right either. Some examples: the Cloudflare dashboard, the Google Cloud console, etc. Just yesterday I was using the HBO Max web app and it was such a disgusting experience. It loaded 2MB of JavaScript for a simple password recovery form. And once logged in it was spinner after spinner after spinner. In some cases even throwing you out to others SPAs when navigating.
- nightpool 4y agoI'm curious: What problems do you have with the Cloudflare dashboard that seem to be SPA-related? I use it regularly, and the only problem I can think of encountering is that it never remembers my "desired location" when it redirects me to a login form—If I go to view the firewall graph (navigating from my browser URL bar with autocomplete based on history), it will send me to a login page and then dump me back onto the big "overview of all sites" page. But this is hardly a problem specific to SPA apps! Every multi-page app I've ever worked on had to implement some sort of "login_desired_location" cookie if they want to get this right, and very few of the apps I use ever get this right—regardless of page architecture. (The Google Cloud console is a complete nightmare, although I would argue that that's more for UX reasons then for SPA-specific ones—it seems honestly like the Google Cloud console is exactly as confusingly stateful and difficult to navigate as every PHP-based cpanel dashboard from the 90s: a hard bar to reach with any type of page architecture!)
- pier25 4y agoMy main issue with the CF dashboard is that it's spinner-hell. It's fast, but there are spinners and layout shifts everywhere. Regarding the GC console, it has many UX issues, but regarding the SPA architecture my main complaint is that it's extremely slow and bloated. Every interaction takes seconds. Opening something on a new tab takes seconds. And there are spinners everywhere. I have to admit they recently pushed a new version that downloads less JS, but it's still pretty tedious to use.
- superdimwit 4y agoDisappointed this wasn't an article about bath houses
- dwheeler 4y agoAnother issue: not everyone has JavaScript enabled, and it's good to back off to something useful without JavaScript where that is sensible. Many security-minded folks think that "auto run arbitrary code from random websites" is more dangerous than the alternative. Indeed, this isanifestly true. Many sites should be able to provide a useful service without JavaScript. Sure, that's unreasonable for some sites (like Google docs), but for others it is perfectly reasonable.
- Graffur 4y ago> not everyone has JavaScript enabled What are the stats? I assume it's > 99% have JavaScript enabled. Any significant percentage could be down to corporate policies.
- HWR_14 4y agoStupid question, but given that most analytics are gathered via JS, I wonder if that might fall into the same sampling bias as "we called 100 random people and everyone has a phone!"
- Graffur 4y agoIt's a good point. I'm not sure how it would be tracked. I just can't think of anyone I know that even might browse with JS off. It's on as a default setting and I think it is fair to say that most of the world don't know what JS is.
- HWR_14 4y ago> I just can't think of anyone I know that even might browse with JS off. Hi new internet friend. I have it whitelisted for some (perhaps many) sites. But even if it was on, things like google analytics are still blocked (at least I hope they are! Tracking is a never-ending battle)
- dwheeler 4y agoMost people leave JS on, but several browsers (e.g., Tor browser) and browser extensions make it easy to turn ir off (e.g. for improved security). Many tools, e.g. Lynx, curl, wget, do not implement JavaScript.
- jiveturkey 4y agoI get that this is HN, so context is provided, but really the title should be capitalized correctly. 'SPAs' not 'Spas'. You do see the oddball story here, and I was wondering if this was going to be about bacterial profile of hot tubs.
- bombcar 4y agoI misread it as SPAC and then jacuzzi and finally realized what it was referring to once it loaded. Which is sad, because the first two were more interesting to me.
- Alex3917 4y agoI actually posted a piece today, comparing the performance of every website on madewithangular.com with every website from the next.js showcase: https://alexkrupp.typepad.com/sensemaking/2022/06/angular-without-ssr-is-faster-than-nextjs-with-ssr-i-have-the-data.html https://alexkrupp.typepad.com/sensemaking/2022/06/angular-wi... If you look at the distribution of PageSpeed Insights performance scores, it's very clear that choice of framework is not what causes bad performance. The data shows that Angular might be a little better than Next.js for getting top scores, but for the vast majority of sites, the reasons for bad performance have nothing to do with framework. Put another way, the average Next.js site has a performance score of ~35, which is terrible. If you were to rewrite your site in Svelte, then maybe it would go to 36, which is still terrible. Unless you are already spending the money to be in the top 1% of all websites in terms of performance, then you might as well just pick a tech stack at random -- at least as far as performance is concerned, obviously there are other factors at play. To make this even more concrete, let's say it would take 18 months to rewrite your front end in Svelte -- so ~3,000 hours to get an expected PageSpeed Insights improvement of 1 point. Alternatively, let's say it takes 5 hours to replace Moment.js with Day.js, which has an expected improvement of 5 points. That means replacing Moment.js with Day.js would be, on an hour-per-hour basis, 3,000x more cost effective than switching frameworks. And yet nearly every time I talk with a startup that is considering doing something about their slow SPA, it's usually just spending millions of dollars to rewrite it in some trendier framework.
- dieulot 4y agoThis article compares the CPU times of every site using Angular/React/Vue/jQuery known by the HTTP Archive and comes to a very different conclusion: https://timkadlec.com/remembers/2020-04-21-the-cost-of-javascript-frameworks/ https://timkadlec.com/remembers/2020-04-21-the-cost-of-javas...
- Alex3917 4y agoIt looks like the author has come to a fairly similar conclusion, albeit from measuring something completely different: "It’s worth noting that because sites with React or Angular spend more time on the CPU than others, that isn’t necessarily the same as saying React is more expensive on the CPU than Vue.js. In fact, it says very little about the performance of the core frameworks in play and much more about the approach to development these frameworks may encourage (whether intentionally or not) through documentation, ecosystem, and general coding practices." CPU usage is vaguely interesting, although I assume the vast majority of people care more about their page load speed. I'd also note that relying on technology detection from some third party is potentially going to be very misleading, unless that data is actually regularly updated. Sites change their technologies all the time, so even a significant percentage of the sites from the Next.js Showcase and MadeWithAngular.com aren't actually made with those technologies. Unless you take the time to either go through each site by hand, or else pull out the code from the Chrome extension for each framework to detect its presence in the way that the authors of that framework endorse, then you could easily have ~30% of the sites for each technology no longer actually using that technology.
- ravenstine 4y agoA single page app is nothing but JavaScript that can render pages without a full refresh. That's it. People seem to have this idea that a single page app is something else, in particular an app with little to no server generated pages, but if you even just have Turbolinks then you now have a SPA with some HTML coming from the server.
- encryptluks2 4y agoI find when most people refer to SPAs they actually mean PWAs
- em-bee 4y agoPeople seem to have this idea that a single page app is something else, in particular an app with little to no server generated pages what are you trying to say? not generating pages on the server is the primary benefit for SPAs in my eyes. that's why i prefer to build SPAs even for trivial sites. because it drastically simplifies the backend. i don't have any site specific logic in my backend anymore. it's just a data storage. CRUD. i can reuse my backend for almost any site without modification. sure, you can build SPAs while still generating html on the server, but for me that completely misses the point. the only html that is coming from my servers is user submitted static content.
- francisofascii 4y agoSome developers prefer generating HTML in server side logic using server side templating tech. (Rails. C#/Razor) So when that is the case, the only benefit of SPA is avoiding a page refresh.
- miiiiiike 4y ago> "right down to esoteric topics like memory leaks. (Do you have a team like that?)" Y..You... Your team thinks memory leaks are an esoteric topic?
- teg4n_ 4y agoIn frontend web development absolutely.
- klysm 4y agoAs is most computer science lol
- chrismorgan 4y agoBack then, there was no good tooling for the topic.
- iamben 4y agoGreat article. In the 'real world' of my own little bubble, The average SPA is worse than the average MPA seems to come up pretty regularly, particularly in the ecom world. I'm seeing more new sites being built as single page apps without any real need for them to be. Having been agency side in the past, it feels like either the businesses needing a new website are being sold some slick pitch about how SPAs are the future, or the devs have decided to reinvent the wheel because making MPAs is boring. Both are usually to the detriment of the end product. When the new SPA site materialises there are SO many problems. Each one takes monumental effort to fix, because of stupid intricacies. External services stop working with it. Remember that thing the marketing team had been using for the last year? That no longer works; cue 3 months of reporting gaps. And that other thing you had in your tag manager? That now loads with every refresh (or not for any subsequent page!), and the JavaScript breaks after the first load. The data layer? See ya! SEO? See ya! Those Adwords gclids? "Oh we stripped those..." Etc. Etc. Etc. I think a lot of the problem comes from developers not being in the weeds with the end product. 25 years of 'normal' sites and even the bits you don't know personally work pretty well. Stuff is solved. If you're the dev tasked with creating a new ecom site, if you've never had to put heatmaps in GTM, or enhanced ecommerce in the data layer for a checkout plugin - or whatever else - how do you know to build it in your SPA? And it's never going to be specced, because most end users just expect stuff 'works'. I've used some brilliant SPAs. But jeez - do it well or don't do it at all. And 'well' shouldn't be judged by the developer.
- night-rider 4y agoYeah does every site need Gmail levels of complexity when simple HTML and a sprinkling of CSS will do the trick instead? There are people who disable JS for accessibility reasons and are locked out of reading certain text just because it requires JS. Then there’s the remarkable low effort of what’s put into the <noscript> tag. No description apart from the familiar: ‘This page requires Javascript’
- corrral 4y agoGmail doesn't even need gmail levels of complexity. The "basic HTML" version is already pretty good, and some very light extra javascript could easily cover what few gaps it has, no need for an SPA.
- Yhippa 4y agoThe biggest downside to SPAs are that a lot of retail eCommerce companies seem to have built average SPAs. I've run into cryptic error messages when trying to do some kind of transaction ranging from mundane (buying toilet paper) to high stress or important (buying plane tickets for a work trip next week). Worse yet, seeing no error messages and going into the web browser's dev console to see the error message. A lot of companies over the past 15+ years flew too close to the sun that don't have the competency of Amazon or Google to build SPAs well.
- julienfr112 4y agoAmazon is MPA, right ?
- datagram 4y ago> the competency of Amazon or Google to build SPAs well Given how frequently the YouTube SPA screws up back button behavior, I don't know if Google deserves to be in the competent bucket. And as far as I can tell amazon.com is still a MPA, which maybe says something given that this is a company known for doing research on now page load times affect their profits.
- deleted 4y ago[deleted]
- rand0m4r 4y ago> and multi-thread that JavaScript yeah ...
- brundolf 4y agoThis can be generalized to any opinionated technology: making a platform/language/whatever more opinionated lifts the average case, and lowers the ceiling. This is one of many pervasive and recurring trade-offs in our industry. The web is an opinionated platform, that has this giant escape-hatch called JavaScript. If you choose to go off-roading, you have more power and also more responsibility.