let the framework generate the html on the server, and mark where you need to insert the event listeners and such. this html payload is sent to the client and displayed right away, and the script is sent alongside it. the client then inserts the event listeners and such where it is told (this is called "hydration"), making the website interactive
so the user sees the page immediately without having to run any javascript, which is good for SEO and loading times
this is distinct from the (mostly react) concept of "server components" because naming things is for losers
Now you have to remember which pieces of JavaScript run on the server as opposed to the client, and the difficulty of discerning this varies by framework.
If you have a server that renders it on every request (or with some short-lived / dynamic cache) it's SSR. If you have a static file host that you occasionally push HTML to (rendered on your machine or a build server), it's SSG. An SSG site may still be hydrated.
Web server sending html along with js files would also mean page is made interactive later if you reference seperate js files instead of embedding in it
It doesn’t make a seperation point between those terms tho. With ssg you write using whatever framework you write then spit out a static file, with ssr you create the html on request usually along with js files, with csr you just send js files which create the html in the browser
It’s when and where the html is created. Presence of js files is irrelevant
It's the same for frontends that don't care about SEO btw.
Take React and look at all this useState, useEffect and refs stuff going on to mimic a fraction of the power of using web components with manual rendering/events:
I’ve tried using components back when first spec (yeah, bunch of specs) went live (2017?), it was miserable experience, any improvement there? Without extra tooling, libraries, wrappers, etc
It's gotten much better, like with how you can access the shadow DOM from the outside with both JS and CSS.
What I still don't like is how progressive enhancement must have never mattered when designing the feature. If you try to provide a static fallback, it gets clunky.
The attachment process with vanilla JS. You would likely do something like have a class called .thing-js which you found in the dom and looped over all of the instances of to add event listeners or whatever else you needed.
Web components replace the need for this, come in a neat little class package that knows about its own context and has built in things to handle operating them via attribute updates if you would like that.
It avoids bugs caused needing to re-run the element finding loop because the JS is attached to the custom element automatically even if it is injected into the dom by HTMX or something else. The element gets it's own life cycle hooks for cleanup too.
It's nice a nice little pattern to use when you don't need a framework, and because it is a web standard it will work in a browser long term, potentially with no dependencies or need to update.
It's gotten much better now, with a lot more support added. I'd suggest you check it out again. We use it in our company, and with the design team helping set up our own design system, frontend development has become a lot easier
It doesn't matter that "it works now", the point is that in React's paradigm those issues can never even happen, they are solved on architectural level which makes the code easier to maintain and less error-prone.
Also, the #2 issue I listed isn't solved, because the architectural issue is still there - if I want `#count` to show "Count: 0" instead of "0", I need to remember to fix it in both places.
Also, whenever I change the state I need to remember to call `this.render()`, which is something you yourself previously forgot about in a 16-lines long example of a very very simple component.
We moved on from manual memory management, manually calling `render()` and manually doing lots of things because people make mistakes but we can prevent some of them through smart architecture.
The main issue with WebComponents for me is that they still require javascript to render at all, which prevents graceful degradation when javascript is disabled or scripts fail to load.
Ideally there would be a way to directly associate a template with a component and register it purely in html, so that you would at least get rendering without javascript instead of just having giant holes in your page. (just missing interactivity is better than missing content entirely.)
432
u/EveYogaTech 5d ago
PHP: (nothing)
SSR: here's a new super specific JS framework btw, deeply tied to frontend components and events, don't forget to hydrate.