13 ms·
It's been so frustrating watch this play out over the past decade. I keep seeing projects that could have been written as a traditional multi-page application
by simonw 5y ago
It's been so frustrating watch this play out over the past decade.
I keep seeing projects that could have been written as a traditional multi-page application pick an SPA architecture instead, with the result that they take 2-5 times longer to build and produce an end-result that's far slower to load and much more prone to bugs.
Inevitably none of these projects end up taking advantage of the supposed benefits of SPAs: there are no snazzy animations between states, and the "interactivity" mainly consists of form submissions that don't trigger a full page - which could have been done for a fraction of the cost (in development time and performance) using a 2009-era jQuery plugin!
And most of them don't spend the time to implement HTML5 history properly, so they break the URLs - which means you can't bookmark or deep link into them and they break the back/forward buttons.
I started out thinking "surely there are benefits to this approach that I've not understood yet - there's no way the entire industry would swing in this direction if it didn't have good reasons to do so".
I've run out of patience now. Not only do we not seem to be learning from our mistakes, but we've now trained up an entire new generation of web developers who don't even know HOW to build interactive web products without going the SPA route!
My recommendation remains the same: default to not writing an SPA, unless your project has specific, well understood requirements (e.g. you're building Figma) that make the SPA route a better fit.
Don't default to building an SPA.
- fennecfoxy 5y agoIdk I don't think the problem is the SPA itself, it's bad design patterns that that make it terrible as you say. I think really clean, performant SPAs can definitely be written and I think the overall experience of using a SPA can be much better than a multi-page site if the task at hand requires it. There should be two parts of the web now really: * Traditional multi-page websites * SPAs that could have been a native app on the device, but are much more accessible in web form and without requiring an install
- midrus 5y agoThe alternative to SPAs is not 90s pages reloads. Nowadays you have livewire, hotwire, unpoly, htmx and several other modern solutions.
- baby 5y agoI suggest we go back to iframes
- deleted 5y ago[deleted]
- finniananderson 5y agoTotally agree. We built a product in ~5 months with real-time collaboration, extensive interactivity, Oauth, Stripe and Gmail integrations with a standard Ruby on Rails stack. It's rock-solid, performant, dead-simple and extremely productive to work with. Why're we throwing away years of learning to build unstable, complex and inaccessible applications?
- arvinsim 5y agoBecause the majority of developers will gravitate towards tools that will give them the best employment opportunity, not necessarily the best tools for the job. TL;DR Resume Driven Development
- midrus 5y agoSame experience here, in our case with Laravel. The project started as a Next.js SPA and after we needed to add authentication, translations and background jobs things became so crazy and so "custom" that we ditched it and in almost 2 weeks had everything built in a much more robust way with Laravel and Livewire + Alpine.
- kshahar 5y agoWhat approach did you take with real-time collaboration and interactivity? Is that part still rendered client-side?
- whatshisface 5y ago>Why're we throwing away years of learning to build unstable, complex and inaccessible applications? 1. Smart people seek out difficult problems. 2. Difficult problems drive the creation of complex, niche tools, that bear cultural associations with the smart people who made and use them. 3. People who want to be smart seek out complex, niche tools.
- heyitsanewacco 5y agolmao yeah pretty much. I'm moving from a low code shop to Node/Vue because I can't keep people. They all want to pad their resume, so I'm going to build at 2x the cost just so I can keep the projects going.
- krisrm 5y agoI always thought of the benefits of SPAs more as a separation-of-concerns thing. You can pretty effectively build a functional front-end web application and mock a set of back-end REST apis, while another team builds out a the back-end. There are absolutely tradeoffs, and being a good software engineer is about understanding where and when those tradeoffs apply.
- simonw 5y agoThat's definitely true at the organizational level, and it's an argument with some merits. In practice though, I've seen this backfire. You end up with the frontend team blocked because the API they need isn't available yet, and then the backend team gets blocked because they shipped the API but they can't use it to deliver value because the frontend team don't have the capacity to build the interface for it! My preference is to work on mixed-skll teams that can ship a feature independently of any other team. I really like the way Basecamp describe this in their handbook: https://github.com/basecamp/handbook/blob/master/how-we-work.md#in-self-sufficient-independent-teams https://github.com/basecamp/handbook/blob/master/how-we-work... - "In self-sufficient, independent teams".
- ngcazz 5y agothat sounds like a mismatch between the architecture and how work is getting planned no? if the backend is in the critical path to delivering the user value of a feature then the backend and frontend engineers need to be developing (and testing) the feature together
- lazide 5y agoThey ALWAYS need to be building and developing the feature together or this happens. Decent API design without deep understanding of Client implementation or performance needs is nearly impossible. They generally should all be in the same team, but that often doesn’t scale. Not having them in the same team pretty much never works well though either.
- ar_lan 5y ago
- evanweaver 5y agoI know people for whom the traditional way of building a web app is completely foreign. I am curious how you would describe the concept and tools to someone who has never encountered them before outside an SPA architecture.
- rapind 5y agoIt’s all about state management IMO. There are legitimate reasons to keep UI specific complex temporary state on the client that would be more complex (and slower) if the server needed to hold it. So an SPA or at least partial SPA in some situations does makes sense. But it does tend to become a hammer for every screw over time…
- polished85 5y agoI initially thought part of the appeal was offloading the workload to the front end, where your processing power scales infinitely with each user's device. Maybe the benefit turned out to be negligible, I'm not really sure. Can server costs be reduced by offloading the work to the front end?
- gnlrtntv 5y agoThey absolutely can, if your workload is ideal for this situation, but unfortunately, the most "expensive" (in terms of time, money, computing power, you name it) part of giving a user information is typically the filtering and collation of that information from a much larger pool of information — almost always a pool of information that is far too big and too private to just send to the client to sort through locally. Even in the most simple scenarios, you quickly find your limits. If you get data back, but it's paginated (and it almost always has to be, for basic reliability reasons as much as anything else), you can't be guaranteed to have the complete set of data in a given circumstance, so you can't perform operations like filtering, pivoting, or sorting that data locally. You have to ask the server to do this for you and wait for the response, just like we've had to in the past.
- somishere 5y agoDynamic loading of content is a feature of SPAs, but it's not a defining feature, nor unique. In fact, one defining feature of SPAs is the offline capabilities (service workers, caching, etc.), which sits at a bit of a tangent to database considerations like this.
- freedomben 5y agoThis was one of the appeals initially, and would certainly still be true if you were doing something very processor intensive that could securely be done on the client. Languages/runtimes have gotten faster and more optimized, while hardware has continued to move forward. It's also far easier now to add more backend instances using orchestrators like k8s, so it's less of a big deal to have to add replicas.
- somishere 5y ago
- com2kid 5y ago> And most of them don't spend the time to implement HTML5 history properly, so they break the URLs - which means you can't bookmark or deep link into them and they break the back/forward buttons. The majority of routers for React, and other SPA frameworks, do this out of the box. This has been a solved problem for half a decade at least. A website has to go out of its way to mess this up. That aside, SPAs are great for a number of reasons: 1. You aren't mixing state across server and client. Single Source of Truth is a thing for a good reason. If you have a stateful backend, and your front end naturally has the state of whatever the user has input, you now have to work to keep those two in sync. 2. You need a beefier backend. A SPA backed by REST APIs is super easy to scale. nginx can serve up static resources (the JS bundle of the site) LOLWTF fast, and stateless REST apis are easy peasy to scale up to whatever load you want. Now you just have to worry about backend DB, which you have to worry about with non SPAs anyway. 3. Less languages to deal with. If you are making a modern site you likely have JS on the front end, so with SPA you have JS + HTML. With another backend framework you now have JS+HTML+(Ruby|Python|PHP|C#|...), and that back end code now needs to generate HTML+JS. That is just all around more work. I agree some sites shouldn't be a SPA, a site that is mostly text content consumption, please no. A blog doesn't need to be a SPA. Many forums, such as HN, don't need to be a SPA. But if a site is behaving like an actual application, just delivered through a web browser, then SPAs make a ton of sense.
- manigandham 5y ago1) JS history handling is fragile. A single error can break navigation completely. There's no built-in loading indicator so sites are left with no feedback or have bloated progress bars. And nothing automatically solves for deep links if the app doesn't use routes for different views or relies on other events instead of hyperlinks. 2) Servers are very fast and assembling HTML is trivial. Browsers are optimized for downloading, parsing and rendering HTML as it streams in. Using JS to write HTML after making multiple network calls is objectively slower than a single network request that assembles everything on the server close to the datastore with minimal latency. 3) Every other language is faster and more capable on the server than JS, and all major web frameworks have modern component-based UI templating. Interactions with roundtrips are just fine, and some light JS can handle most other scenarios. > "an actual application" That's the only reason to use a SPA, not what you mentioned.
- rektide 5y ago> It's been so frustrating watch this play out over the past decade. > I keep seeing projects that could have been written as a traditional multi-page application pick a SPA architecture instead, with the result that they take 2-5 times longer to build and produce an end-result that's far slower to load and much more prone to bugs.* Its been frustrating seeing the webplatform not play out, seeing so little growing in to SPAs, so little maturing. Url-based routing is heavily under-represented, tackes on only by the one or two blokes who happened to have some memory of web architecture. This clairifies the architecture both internally & externally. As bad a problem, single page apps being stuck, forever, at single-bundle apps is phenomenally sad. Splitting bundles into chunks as a manual development task is so hard, so bad. The goal of having web based modules almost made sense, almost happened, but we rafically underinvested in transport technology, cache-digest going undelivered. I continue to think js modules, with import maps- the key tech to making modules modular- is worth it, would help make our architecture so much better. There is mild extra time to first load, but worth it/small, & cached after. Again we're damned though. Years too late to try & see how excellent it would be to have something like react cached & AOT compiled as from a cdn. Because now privacy concern freak-outs mean this huge advantage of only needing to pull & potentially compile a js module once are gone: site-partitioning rules. We could have had better architecture, been using the language not absurd bundlers, and enjoyed high cache bit rates for common libraries. SPAs just didnt care, never tried at all, we all (almost all) did a horrible job & took way way too long (over a decade) to make modules modular g usable. There was so much hope g promise & such abaurd non-delivery, on the module front, on app archtiecture. HTTP3 and early-hints still have some promising hopes for accelerating our transports, making "just modules" a possibility & fast, without careful hand optimization. We could still do more to optimize bundles, have automated tools that analyze up front versus on-demand dependency bundles, build http bundles of these. But i hope eventually itcs mostly not super necessary to build webpackage (nor far worse, webpack) bundles. SPAs still have great potential. More so, now that we finally have some support tech for modules forming.
- craigkerstiens 5y agoHi Simon, why'd you pull me in ;) We recently went a rewrite of our frontend for https://www.crunchybridge.com https://www.crunchybridge.com from SPA to more "basic" request response app and couldn't be happier. Previously was SPA with React and we rebuilt from scratch with request/response using Node. In places we still leverage react components for re-usable frontend bits, but no more SPA and state management. As you've mentioned in some of your other threads on this, the state management and sync between the API team and the front end team just caused velocity to slow down. It took longer to ship even the most basic things. While we want a clean and polished experience, the SPA approach didn't really accomplish any of that for us. The rewrite was under 8 weeks of an app that had been built up over a couple years and we quickly recouped all that time in our new found velocity.
- mwcampbell 5y agoWhat server-side framework did you use for the request/response rewrite?
- craigkerstiens 5y agoIt was all note on the request/response as a basic express app.
- fendy3002 5y agoMy knowledge is limited on the front end. May I know which Node framework do you use? Is it NextJS? If not, what do you think about using NextJS because I really consider it a better approach and want to use it at new projects.
- craigkerstiens 5y agoWe were actually less framework than more. Basic express app. We explored Next and almost went that way.
- Graffur 5y agoThat just sounds like poor performing developers to me. You don't need snazzy animations between states. Just not reloading the full page is a benefit.
- lolinder 5y agoWe have a PHP app that doesn't reload the full page. We use jQuery's .load(), which has been around since 1.0: https://api.jquery.com/load/ https://api.jquery.com/load/
- Graffur 5y agoOkay - build a complex site with JQuery and see how it goes..
- midrus 5y agoThen you can use Livewire, Unpoly, or HTMX. MVC doesn't mean 90s style reloads anymore.
- lolinder 5y agoThat's what I'm saying: I maintain a complex web app that is built with PHP-templated HTML with jQuery sprinkled in as needed to make things more interactive. It's not perfect, but it's a far cry from the nightmare that people always seem to imagine when they think of "the jQuery days". Would I use jQuery if I redid it today? No. But this app does prove to me that progressively-enhanced HTML is a valid path to an app today, it doesn't need to be an SPA.
- apatheticonion 5y agoI really view it as the opposite. Prefer the writing of an SPA or serverless MPA. If you consider that native desktop and mobile applications are siloed applications that coordinate with an API to achieve tasks - this is basically how SPAs or serverless MPAs work. Part of the reason this is effective is because of the low cost nature of deploying applications like this. For example; I can write a calorie counter that stores records in the client via indexeddb. Given all the work is processed on the client, using an http server would be an unnecessary maintenance burden as it would simply server static files. Rather than host the web application via a self managed http-server, I can just put my html files on S3 making hosting it free and unmanaged. Should I decide I need to add user accounts and cloud storage - well I can then create a backend that exposes API endpoints to facilitate the tasks. Those endpoints are then compatible with native applications, should I decide to write native mobile and desktop variations of my web application. Furthermore, with Web Assembly expanding to offer the ability to write web applications using languages like C++, Rust, C#, Golang and the browser expanding access to OS subsystems like filesystem access - what we are seeing is that the browser is becoming a sandboxed UI toolkit, much like GTK or QT (except without native styling). If there was anything that would empower Linux Desktops to be compatible with productivity software - it's progressive web applications. Consider that Photoshop and Office are accessible on Linux via web today.
- midrus 5y agoYou're describing an actual client side (mobile or desktop) application made with web technology, not a web application. That's a fair use of SPA tech. As soon as you need authentication, showing data across users, allowing visitors to see shared data, perform validation of inputs, send notifications when other user action happens, etc you're back in SPA hell.
- apatheticonion 5y agoWhy do any of those attributes put you in SPA hell? If you were to write an Android application that featured Authentication, would you also be in "app development hell"? Languages, performance and UI decorations aside - it's basically the same thing, no?
- newhotelowner 5y agoExample wealthfront. All pages are SPAs. I mean, page A is SPA, page B is another SPA and page C is another SPA.
- outworlder 5y agoWhen SPA started picking up steam, I thought it was an amazing development! We had gone from mainframes, to personal computers, and were back to mainframes and using our powerful machines as glorified dumb terminals. This way, we could have UI code running locally, and servers only handling state. Plus, less data to transfer! Then the frameworks ballooned in size. What previously was seen as wasteful (rendering and sending HTML) started to seem pretty frugal in comparison to the multi megabyte pages. Not to mention that one could always send just page fragments. Other than specialized apps, I think most single page applications are a mistake. Sure, some may benefit from a nice UI - say, I'm writing a 3D modeler. But most apps there are could just re-render pages. 'Refresh' is not much of a problem in an age where simple REST API calls are returning megabytes of JSON data...
- coruja 5y agoI try to tell myself "don't get caught up in using a fancy frontend framework on this one," as I'm starting a new project, but I keep running into situations where my functionality would just work so much better. As an example, I was writing a tool the other day to automate some things that have to do with quotes for my 9-to-5. Being able to add inline functionality in Django to select a customer within the quote page, or add / edit a new customer without having to leave that quote felt very 'hackish,' using the same jquery callback method used in Django Admin. My point is, this feels like very basic functionality, but turned into a whole other ordeal using traditional methods.
- porker 5y ago> Being able to add inline functionality in Django to select a customer within the quote page, or add / edit a new customer without having to leave that quote felt very 'hackish,' using the same jquery callback method used in Django Admin. Agreed. For form based apps I don't like to fall back to SPAs (bloat, the desire of every dev to reinvent forms in their framework, client and server side validation duplication), and yet working with relational data they are easier. It's one of those places where a half-way step would be so useful.
- scrapcode 5y agoThat is something I hadn't really taken the time to compartmentalize and articulate, but a js framework that focused on forms only would be wonderful. I'm sure that someone has taken a stab at it. Something like crispy-forms that added the ability to add components for variable data such as inlines... I'm guessing that Vue.js may be a good drop-in for this, but it has been a while since I have used Vue.
- stevage 5y agoSpeaking for myself, I find it much quicker and easier to build an SPA than a server rendered app. You seem to take the stance that server rendered is the default, normal way to architect and SPA requires justification for its aberrant departure from the norm. SPA have lots of advantages: fewer languages to learn, easier to deploy, etc.
- lolinder 5y ago> SPA have lots of advantages: fewer languages to learn, easier to deploy, etc. The two examples you give are only true if you don't have a backend at all. As soon as you have a backend, you're back to having to pick a backend language and deploy a backend server. If your app doesn't need a backend, then I'd agree that an SPA is the way to go.
- neon_electro 5y agoI think the person you're replying to is implying using JS/Node for both front- and back-end.
- jimmont 5y agoDon't don't do what I would do. The mistake is forgetting first principles. You don't do something good by focusing on what not to do (like don't be evil). Focus on what to do: KISS, YAGNI, etc.. even DRY is a far lower priority. Software, especially frontend and web are rampant with problems from operating as an echo chamber. Just consider what Ryan did with Deno and had to say criticizing his first project. Yet folks are still wildly supportive of the older technical decisions and go to great lengths to preserve those same mistakes.
- ksec 5y ago>Not only do we not seem to be learning from our mistakes That is a lot of good faith. What happens if they were not mistakes? But deliberate attempt to push Javascript as the one and only de facto approach to web development and Resume Driven Development? I recently asked this [1], I dont want to name names, but do any tech company actually apologise after their high evangelism to the world and industry and walk back 70% of their decision five years later? And for some strange reason this mostly happens to Web Development in general. [1] https://news.ycombinator.com/item?id=30451916 https://news.ycombinator.com/item?id=30451916
- notatoad 5y ago>e.g. you're building Figma i think what it comes down to is if you have to make a decision of "should i build an SPA?" the answer is no. the web is good at doing pages. if your app has pages, use the web's default page mechanism. and i don't say this as a hater of single-page apps. i love webapps, and i think that building a webapp should be the default for most cases. there's a lot of apps that don't naturally break into a "page" metaphor, and all the technologies that are part of the single-page app concept are great for those cases. figma is a perfect example, because there's no obvious division between what would be one page versus another. it's not a paginated website that has been built as an SPA, it's literally just one page that has a whole bunch of interactivity.
- Ziggy_Zaggy 5y agoTotally agree.
- zh3 5y ago>....taking advantage of the supposed benefits of SPAs: there are no snazzy animations between states.... If that's the main benefit, let's hear it for MPAs. I want a website that's fast, responsive, clicky, sharp and to the point - not some soft-focus pastel cartoon movie. As the author says, that's fine for audio/video sites (and reasonable for other entertainment-focussed sites) - for information sites it just gets in the way (animated elements - especially persistent ones - are a terrible idea when trying to concentrate on textual content).
- mmis1000 5y ago> not some soft-focus pastel cartoon movie. For some reason, designers likes it no matter it makes sense or not, so it is what you get. The current designer trending is just a shit show, nuke the usability for nearly no benefits IMO.
- shroompasta 5y agoI mean, of course the co-creator of Django would say this. I wouldn't recommend newer generation of developers to build traditional web apps, let alone use jQuery. I don't understand why people think we're still in the age of form submissions and blog posts - There has to be a good majority of us here that has worked on something complex that required SPAs here, no? Not only would it be detrimental to a young developer's career to suggest avoiding SPAs in regards to hiring, but only limiting that developer to create blog post styled content is severely restraining. Let them develop their blogs in SPAs, at least when they are needed to go into something a bit more complex, they at least have the foundational knowledge required to move towards that. What you're suggesting is to learn two things, (one that is inevitably being phased out), and spend the mental effort to discern when to use either one, when the more beneficial alternative is to learn SPAs and just go with it. No 18-25 year old is trying to make a Weblog where walls of text is the main content - Youtube shorts, instagram reels, tiktoks and all these bite sized content has done a great job at destroying that level of attention span. They're going to be building something else, something quick and visual, something pleasing to the eyes - and more often than not, it's going to require a SPA.
- CRConrad 5y ago> I don't understand why people think we're still in the age of form submissions and blog posts Because we are. > There has to be a good majority of us here that has worked on something complex that required SPAs here, no? No. Because complex stuff doesn't require SPAs.
- tored 5y ago> There has to be a good majority of us here that has worked on something complex that required SPAs here, no? You can still create a something complex without using any of the common SPA techniques, instead you can use things like Hotwire, Livewire, htmx instead.
- shroompasta 5y agonot practical for hiring. and although I find it intriguing that hey.com is using Hotwire, it's still insignificant compared to some SPA framework's ecosystems. Performance isn't an end all be all, otherwise we should make another article and say "Python and PHP was a mistake for web servers" There is some give to be had for the sake of practicality.