Live data from Hacker News

The absurd complexity of server-side rendering

gist.github.com

71–80 of 395 posts

Re: The absurd complexity of server-side rendering

#71
post #54

Earlier quoted context omitted.

Not really, because any JS/HTML logic that you have needs to be downloaded into memory and compiled and interpreted by each client independently. Then, once loaded, any server-side data needs to be fetched from an API request and injected into the page in the proper place. Server-side rendering saves at least one round trip by fetching the data from the database and injecting it on the server side before sending the…

> Not really, because any JS/HTML logic that you have needs to be downloaded into memory and compiled and interpreted by each client independently I see my question was unclear. I did not mean compute/bandwidth "in totality", I meant "in costs that would be invoked by the application owner". > Server-side rendering saves at least one round trip by fetching the data from the database and injecting it on the server sid…

> Sure, but the first hit would've been a cache hit anyways.

Similarly, a serverless function that is "warm" already has all the logic needed to inject the static template into memory. It simply needs to call out to the database, which is physically closer to the server, and always quicker, without the need for an additional HTTP handshake...and then inject the data into the template, before sending it down the wire.

> CDN would have the static bundle "at the edge" already for you.

The static bundle just saves on download time. The bundle still needs to be loaded into memory on the client to create the Document Object Model that powers every webpage. Depending on how your client-side bundle is structured, it may be 100ms or 1s before it even begins to make the outbound request back to the API to fill in the necessary data to power your BI dashboard or whatever your use case is. And that's if your BI dashboard was structured to be optimal with all requests rolled up into one (additional architectural effort, easier to satisfy on SSR with multiple database hits having less impact to performance).

Edge functions like Cloudflare Workers have 0ms cold starts.

We're talking tiny fractions of a penny per request. For example, Cloudflare Workers have 100K free requests per day and then its $0.15 / 1 million requests after that.

Better user experience, and it might cost you pennies more per month vs. static + round-trip.

Re: The absurd complexity of server-side rendering

#72
post #26

This isn't real "server side rendering". This is just generating simpler HTML. Real rendering on the server would mean sending a canvas or an image or video, like "cloud gaming". All this complexity seldom translates into sites that do much. There are real "applications in the browser" that let the user do something, but those are rare, and most are toys. Most of them could have been written in Flash, anyway.

SSR in terms of webdev means what this post describes: generating HTML on the server. “Rendering” is a bit of a misnomer; a more apt title would be “server side HTML generation”, but that’s a bit long.

The alternative to SSR is CSR (client side rendering). Think React SPAs.

Re: The absurd complexity of server-side rendering

#73

There are cases when server-side rendering (without SPA) is easier and faster. For example: documentation sites, blog-like sites, internet stores, sites like Hacker News. In all these cases, you can save on development time by writing just one application instead of two (server and client), and improve performance (no need to load multimegabyte JS applications and make multiple AJAX requests to display a page). Of co…

> documentation sites, blog-like sites

Sites like those can often be fully static sites.

Process the docs or the blog posts into HTML. Nothing is generated at runtime. Of course you can cheat a tiny bit, like putting the date in the footer, or cheat a lot. Life's a lot simpler if you don't cheat at all.

Re: The absurd complexity of server-side rendering

#74

I gave it a shot at one startup using next.js that wanted to pre-hydrate redux state, but also use tracking with session cookies et al the regular bag of beans. I spent maybe 6 weeks on it and basically I grew to realize I was in a miasma of pain. I didn't last much longer. I could've wrote the entire thing just vanilla js/css in probably a weekend... So I can commiserate with this.

I'm always impressed by the labyrinthine towers of JS and frameworks people create to ship out relatively simple sites and web apps. By impressed, I mean that I look upon them both in awe and in horror. And I'm guilty of building them myself, as well.

One of the worst things is opening such a project that was written 5+ years ago by someone other than yourself.

Re: The absurd complexity of server-side rendering

#75
post #73

There are cases when server-side rendering (without SPA) is easier and faster. For example: documentation sites, blog-like sites, internet stores, sites like Hacker News. In all these cases, you can save on development time by writing just one application instead of two (server and client), and improve performance (no need to load multimegabyte JS applications and make multiple AJAX requests to display a page). Of co…

> documentation sites, blog-like sites Sites like those can often be fully static sites. Process the docs or the blog posts into HTML. Nothing is generated at runtime. Of course you can cheat a tiny bit, like putting the date in the footer, or cheat a lot. Life's a lot simpler if you don't cheat at all.

Sites like those (e.g. Wikipedia) tend to be driven by a CRM on the backend, with content maintained by a team of people, and so it's not super reasonable for the site to be regenerated and the static HTML file to be reuploaded to the server on every change. Cache the body page, put the timestamped footer on it, and serve it up. Easy peasy, been doing it since 1995.

Re: The absurd complexity of server-side rendering

#76
post #62

Earlier quoted context omitted.

SSR is generally for SEO and performance

Googlebot can render with javascript now, so why do we still need SSR for SEO?

Not reliably. From my experience, the major search engine bots only see whatever is in the DOM until the DOMContentLoaded event or first X seconds which doesn't always see everything due to JavaScript's async nature.

You're also screwing your social media presence since most sites (Facebook, Twitter, Discord, etc.) only read the open graph tags of the initial document since they need instantaneous results.

Re: The absurd complexity of server-side rendering

#77
post #73

There are cases when server-side rendering (without SPA) is easier and faster. For example: documentation sites, blog-like sites, internet stores, sites like Hacker News. In all these cases, you can save on development time by writing just one application instead of two (server and client), and improve performance (no need to load multimegabyte JS applications and make multiple AJAX requests to display a page). Of co…

> documentation sites, blog-like sites Sites like those can often be fully static sites. Process the docs or the blog posts into HTML. Nothing is generated at runtime. Of course you can cheat a tiny bit, like putting the date in the footer, or cheat a lot. Life's a lot simpler if you don't cheat at all.

Heavily cached server-side rendering and statically generated sites kinda converge at some point to the same thing

Re: The absurd complexity of server-side rendering

#78
post #17

Earlier quoted context omitted.

Adtech needs a lot of JS to work. JS to determine how long they are hovering over this and that element, how long this or that ad is in their view, and so on and so forth. The logical conclusion is that every single HTML element needs to be wrapped in a bit of JS somewhere. Nothing should happen in the users browser that can't be monitored by JS.

So adtech is ruining the web. Everything makes sense now.

"At that moment the monk attained enlightenment."

Re: The absurd complexity of server-side rendering

#79
post #54

Earlier quoted context omitted.

> Not really, because any JS/HTML logic that you have needs to be downloaded into memory and compiled and interpreted by each client independently I see my question was unclear. I did not mean compute/bandwidth "in totality", I meant "in costs that would be invoked by the application owner". > Server-side rendering saves at least one round trip by fetching the data from the database and injecting it on the server sid…

> Sure, but the first hit would've been a cache hit anyways. Similarly, a serverless function that is "warm" already has all the logic needed to inject the static template into memory. It simply needs to call out to the database, which is physically closer to the server, and always quicker, without the need for an additional HTTP handshake...and then inject the data into the template, before sending it down the wire.…

> Similarly, a serverless function that is "warm" already has all the logic needed to inject the static template into memory

Sure, I accept this.

> It simply needs to call out to the database, which is physically closer to the server, and always quicker, without the need for an additional HTTP handshake

I contest all three parts of this.

* physically closer

How can this be guaranteed? You have no control over the closest Edge function vs Cloud Server to the user. It's just as likely your Edge function is farther away from the Cloud Server than the user is, from my view. Perhaps your cloud provider is offering you routing services you claim are superior, but given the nature of my questioning is anti-vendor-lock-in you'll understand I mostly disregard that.

* always quicker

How can this be true? The user's machine is quite nicely guaranteed to be somewhat available for the compute here - they issued the request themselves after all. Your machine, on the other hand, has a good chance of cold starting for this request or being hot because a bunch of other requests are being issued to it simultaneously. Given we have async steps in what the SSR is doing, backpressure from sharing resources with other users sounds worse than what we risk with a client machine.

* without the need for an additional HTTP handshake

Again, your Edge function seems likely to either be cold or busy, so this is only something you can speak about probabilistically

> The bundle still needs to be loaded into memory on the client to create the Document Object Model that powers every webpage

HTML still needs to render a DOM, not sure you're hitting on the right points of the parsing... Plus if this page is meant to be interactive still, you've not gained anything with the initial SSR phase

> Depending on how your client-side bundle is structured, it may be 100ms or 1s to fill in the necessary data

It's just not a big deal, and it's laughable you'd make the example a BI dashboard because you rendered something nice for them initially in maybe 0.5s faster on a median request, in exchange for literally enormous complexity. But a BI user is probably going to be in there for a long time, interacting heavily with client-side JS you shipped and they had to parse and render and then also reconcile/hydrate

> easier to satisfy on SSR with multiple database hits having less impact to performance).

How is this easier to satisfy on SSR? You have minimal advantage on your Edge worker being closer to your database than the user, unless your Edge function is actually just sitting beside your database server. It has to make the same requests and transfer the same data the client would be transferring in order to perform this SSR, there are only savings here if your Cloud provider is offering you big vendor lock-in promotions.

> Better user experience, and it might cost you pennies more per month vs. static + round-trip.

> Cloudflare loss-leader pricing

Unconvincing.

Re: The absurd complexity of server-side rendering

#80
post #7

Earlier quoted context omitted.

And usually leads to a BBOM architecture

I have colleagues using Laravel, and there's nothing muddy-ball about their apps at all. Their code is tidy, modern, readable, and clearly maintainable. In terms of practical effect, frameworks influence developers more than languages do.

The idea of using a "framework" in a language that gets completely reloaded on every new request doesn't make sense - at least I thought a framework was something that wrapped your own code and presented an event loop, etc. You'd want a "library" if you just wanted to improve on the original low quality PHP database connectors and such.

But PHP developers always did seem to have inappropriate jealousy over unrelated languages like Java where there is persistence over requests.

Post reply on HN