|
|
|
|
|
by spinningslate
1216 days ago
|
|
> Modelling your frontend as a bunch of reusable components is a big benefit of frameworks. I think it's hard to go half and half with frontend component and backend templating though. I've heard this before, and just don't get it. I have, can, and do create view "components" in both Django and Jinja2. They're just templates. Templates that get included in other templates. I've never (never) got to a point where I thought "darn, I want to abstract out this foo thing as a component, but can't". When I really want front end interactivity - like charts - then I'll use a JS library or a web component. With htmx, I can even do partial page updates. None of that requires the very significant overhead that React/Angular/whatever bring. >I'd rather use Preact than write vanilla JS for basic state management. I'd rather use the backend. Because it owns the state, and cache invalidation is one of the two hard things [0]. [0]: https://www.martinfowler.com/bliki/TwoHardThings.html |
|
Another big upside of JS components which does not exist in templates is typechecking.
Templates are good if you don't have complex hierarchies and have relatively simple layouts that aren't very dynamic, but they're not the same as components.
JS frameworks have relatively low overhead compared to the total size of most sites. React is ~50kb gzipped. There are also of plenty lightweight options.
> I'd rather use the backend. Because it owns the state, and cache invalidation is one of the two hard things
The backend does not own UI state. If I need to filter or sort a collection I don't want to make a request to the backend. If I need to make a selection I don't want to wait for the backend to respond before the UI updates. And so on.