What? No. Not at all. If you're behind a subpar network, your dynamic HTML web app does not load/refresh/update at all, and your users start to get frustrated because your crappy webpage is broken and fails to even do the most basic things.
This is not the case with SPAs, and some of the most pressing problems they solve: perceived performance, resilience to faulty network connections, and overall improved UX.
Let's put it this way: with SPAs you can design your app to work even without a working network connection. That's how resilient SPAs are to networking issues. How do you pull that off with dynamic HTML?
> but for 99% of websites server-side rendering only has advantages.
No, not really. Unless you cherry-pick what goes into the 99%, even basic CRUD, form-driven pages the dynamic HTML way suffers from a multitude of drawbacks that are no longer issues in SPAs, both technical and organizational.
There is a (high) probability users will close the tab after waiting for over a minute for MBs of JS to download and parse.
I'm not sure what leads you to believe that a SPA requires "MBs of JS" to work. I've worked on a popular SPA deployed to multiple regions and with tons of localization data, and the total payload stayed well below 1MB. Plenty of dynamic HTML content, specially images, require far more than that.
In fact, this very discussion on HN, a very spartan dynamic HTML page, currently requires over 250kB as it dumps all the threads regardless of whether you read them or not. As a contrast, Reddit's frontpage takes 750kB.
And Reddit's frontpage size is 1.3 MB according to one check I did which checks the size of all network calls after loading, etc. and that's WITHOUT all the lazy-loaded content below the fold.
> In fact, this very discussion on HN, a very spartan dynamic HTML page, currently requires over 250kB as it dumps all the threads regardless of whether you read them or not. As a contrast, Reddit's frontpage takes 750kB.
You can use tools like your browser’s developer tools or webpage test to accurately measure this. It seems like that would be a useful skill to develop for accurately reasoning about SPAs and understanding why your beliefs don’t match real users’ experiences.
For example, Reddit.com is actually 10MB of transfer, not 750KB, and it takes 5 seconds to process 6.7MB of JavaScript (47 requests to transfer 1.8MB of compressed JavaScript) which delays the start of rendering until 2 seconds in and requires almost 10 seconds to render the top of the page.
https://webpagetest.org/result/220104_AiDcHT_cf05f20e55718cf...
In contrast, the HN page requires a TOTAL of 62KB to render in less than a second:
https://webpagetest.org/result/220104_AiDcAH_1c302fd66a183aa...
That’s an enormous difference which is extremely noticeable if you don’t have a fast computer and network connection, and that’s before you get to the serious bugs Reddit has because their SPA doesn’t handle errors or session timeouts well (I see this on a near-daily basis).
I have a recent iPhone and the new Reddit SPA lags notably behind the old version, which renders twice as fast and is more reliable because it uses a tenth of the code:
https://webpagetest.org/result/220104_BiDcDZ_9bdbf4482d84584...
There's the difference: HTML-first approach will be able to draw everything using very little resources by the time i've loaded a few hundred kilobytes. With JS bundles i first have to wait for the scripts to load, then the dance of unreliable network-roundtrips starts and can fail in mysterious ways unknown the the browser UI.
Images will not prevent the browser from drawing the window, and they can be lazy-loaded if you consider that's better UX (of course the browser can decide to override that setting to respect user preferences). Time to full render is orders of magnitude better on simple HTML/CSS (what browsers were designed to render) than with a crap bundle that's going to trigger network connections and DOM changes (so full page redraws) in mysterious ways.
Also, i love when my refresh and back button in the browser UI do what they're supposed to do. I'm not saying it's impossible with an SPA, that's just something most SPAs i stumble upon are completely incapable to respect.
I encourage you to run the experiment. Take out an old Pentium 4 with 2G RAM, setup Firefox and in the developer bar (f12) turn on network's throttling. It will not be a realistic simulation as you would need packet loss (which other tools can simulate) but it will certainly help you measure performance and make informed decisions.
When I’ve measured this for real users on moderately busy sites (6 figure daily users, not Google-scale) the reported first page load times tracked the cold cache times for most users (70+%) even for people who’d visited before. If they were geographically clustered (news story, etc.) the cache hits on CDN nodes would be high but you couldn’t count on that.
LOL. I'm yet to see a single SPA which can tolerate a bad network. You certainly have better tools to do it, but it still takes a ton of effort and nobody does it. So it ends up failing in worse ways because now the application just stalls and you don't even get the standard browser errors/timeouts.
Unless SPAs are built as "offline first" I haven't seen a single one which works better than a traditional MVC app in such conditions.
That's the sales pitch but here's what actually happens for the vast majority of time: the user gets frustrated because after 5 minutes the SPA finishes failing to load and all they have a blank page or, if it's a site they visit so frequently that all of its dependencies tree are still in the browser's cache, they get the UI shell but nothing works. As a bonus, the assumption that the megabytes of JavaScript would manage state often means that core web functionality like the back button or reloading do not work so while a CRUD user would be able to hit reload and get the expected result as soon as their network connection improves, the SPA user will have to start over from the beginning.
It is technically possible to build things which work offline but in the real world that doesn't work for most applications for a number of reasons:
1. The app depends on things which need to make network requests — you can give a nicer error page but that's not going to make your users happy.
2. The developers ship updates often enough that cached versions aren't current — e.g. you might have all 50MB of dependencies in the cache but if the user got the HTML referencing different URLs, that doesn't matter.
3. The developers forgot to test that they allow long-term caching or serve-stale on their assets.
4. There's a big difference between being completely offline where the interface status shows down and high latency / packet loss. The most frustrating experience for the users are the latter because things act like they're going to work and if they were doing an activity which changes state it might not be clear whether something succeeded or not. The offline API doesn't work for that and it's almost certain that your SPA doesn't really handle it because:
5. Statistically nobody tests in those degraded conditions so they end up with the Twitter-style SPA where it loads the core of the UI structure but then nothing renders. This is better than a server timeout page only in that it allows you to try to convince the user to be less frustrated.
The reason why this is almost always better for server-side rendering comes down to the increased client footprint of an SPA. With an SPA you're depending on an enormous amount of code to load and run before the user sees anything and there's a lot more that can go wrong in ways you didn't handle, which is why it's so common to learn something is an SPA when you get a “successful” blank page. Servers certainly can have problems but most of the moving parts are under your control so you have better visibility and control, and there's no better way to handle degraded conditions than to depend on them less. If the network is slow, trimming your transfer by 1-2 orders of magnitude is going to do more than almost anything else to improve the user experience.
Most of the time SPA's degrade very poorly and instead of breaking they often appear as if they're somewhat working but the site is actually in a broken state and will need a complete refresh to become usable again.