by zmxz · 4y ago · 0 comments
We used languages like PHP/Ruby to produce HTML/CSS that browser renders. Then Microsoft introduced XHR. Then we started with "saving bandwith" and "page does not to be reloaded" and AJAX was born (although it was Asynchronous HTTP and HTML instead of XML). Then such sites weren't indexed by Google so we started to pre-render content again for the most visited URLs.
And now there's so many buzzwords and bland excuses about server side rendering, such as "SSR improves user experience: users don't have to wait for CPU-bound JavaScript to run on the client".
JavaScript itself is not what makes websites slow. It's the 50 megabytes of advertising material I've to load from various "content delivery networks" that are everything except fast and auto-play videos that I'm not interested in.
Today's personal computers are stupidly fast, smartphones too. There's so little gain in the argument that pre-rendering the first request on the server improves performance while it does nothing for the network-related problems (resolving the domains and transferring so much content).
SSR is great, don't get me wrong, but the reasoning that encourages devs to use it is misplaced (not WRONG, misplaced).
Yes, it does improve user experience, but it doesn't do so because our computers are slower in parsing and executing JavaScript.
It is, but not inherently. Lots of sites are shipping:
- far too much of it, even if it’s not in use
- wildly inefficient code which blocks unnecessarily
- lots of stuff cobbled together from third parties without regard for its impact
- far too much on load, both in terms of payload and what gets executed right away
This isn’t just advertising materials or whatever. Most of these points are true by default with eg a Next.js site, even if it’s also SSR/SSG.
If it is not public (like a web app you log into say canva) then SPA is fine and for most public stuff static pages (generated or cached dynamic pages) are fine.
The reason we do SSR is because we want developers to use the same language, libraries and frameworks in the frontend and in the backend. I just don't know which kind of developers are those who cannot bother to learn something else besides JS/TS. I have heard many times the argument "we are saving developer time by using the same technologies everywhere!", but I just don't buy it.
IMO, there's only one gain to SSR and that's the one you can instantly feel when using the app - it's that the page load seems faster. That's it. Added benefit is that your app/site can be indexed by search engines since there's no XHR going on that has to fetch additional data for that first request.
Using the argument that dev does not have to learn something else in the technology world - I never liked that reasoning. We, developers, use tools. Languages are tools. I, and many that I worked with, learn multiple langues over the time, whether they want to or not. I don't know a developer that doesn't know, at least, how to use CSS next to using JavaScript. That's simply what our area of work requires. If one refuses, doesn't want to or can't learn an additional tool - well, is that a developer or code plumber?
I’ve done a couple of openapi-based systems recently and it’s a pretty good experience. I can generate server and client stubs next to models in various languages.
We deliver the HTML to the client, hydrate, and everything works seamlessly.
Since the static and dynamic views are built from the same code, we never have to worry about any disjunction where they fall out of sync.
Also hot reloading a live JS view is a lot faster than restarting the Django server, and refreshing the page.
It’s not that the team doesn’t want to learn Mako or Jinja or another language (heck one of our members designed their own language for fun) but it’s simpler and better to use JS.
If it was another project maybe the trade offs would work out differently though.
SSR is also part of a larger story of optimization which touches upon network concerns, such as making network requests on the server rather than on the client.
Widespread use of ad blockers hints at what users actually want. (Not what developers say they want.)
I get the most from the web by using a text-only browser that does not run Javascript. Page retrieval is fast and generally consistent in speed.