News for hackers. Stuff that matters.
Re:Django, HTMX and Alpine.js: Modern websites, JavaScript o... by resoluteteeth on Tuesday November 23, 2021 @12:18PM (#29320396)
One major downside to HTMX is that as soon as there is any state you have to keep track of, you're teleported back to the late 90s or early 2000s where you have to keep track of all your state in hidden form fields, and you're extremely constrained in how you update pages.

IMO, it's annoying enough that it's probably not worth it unless you're doing something trivial. If you want to render html on the server you can still do that, but in many cases it is easier to just use custom javascript and maybe even receive the rendered html as json to simply updating pages rather than use htmx.

Re:Django, HTMX and Alpine.js: Modern websites, JavaScript o... by nlitened on Tuesday November 23, 2021 @01:25PM (#29321234)
Yeah, those damned early 2000s when back/forward buttons worked perfectly and we didn't lose the entire rich client state upon page refresh or wireless internet hiccup. Thank god we have a lot of JavaScript libraries and ambitious programmers to save us from those trivial things :)
Re:Django, HTMX and Alpine.js: Modern websites, JavaScript o... by kiawe_fire on Tuesday November 23, 2021 @03:59PM (#29323454)
But those were actual problems back then, and they were solved only through significant engineering work to hide them, each of which had their own problems.

Frameworks like .Net WebForms were created to abstract and hide a lot of this from developers, with things like long encoded strings of "view state" that would be re-posted on each request, by serializing things to the URL, or by saving them to Cookie-backed sessions.

But each of these has issues, from privacy concerns using the URL, to security concerns with the "view state", to concurrency and integrity concerns with sessions.

IMO, the biggest reasons these didn't stand out as huge problems in the early 2000's was because:

(a) we didn't use the web like we do today, and our expectations were very different in how things would work if we, for example, added an item to a shopping cart

(b) most heavily interactive / app-like things that more closely work "the way we expect" today, were either still done as desktop apps (like business software) or were implemented as Java applets, Flash, or something else of the sort

(c) in the rare cases that neither (a) nor (b) applied, it was because some very good engineers put in a lot of work to make it work that way.

Re:Django, HTMX and Alpine.js: Modern websites, JavaScript o... by phist_mcgee on Tuesday November 23, 2021 @06:51PM (#29325165)
You mean when a page refresh asked us if it wanted to resubmit a form?
Re:Django, HTMX and Alpine.js: Modern websites, JavaScript o... by nlitened on Wednesday November 24, 2021 @03:35AM (#29328011)
We did this standardized simple trick to prevent this: https://en.m.wikipedia.org/wiki/Post/Redirect/Get
Re:Django, HTMX and Alpine.js: Modern websites, JavaScript o... by jon1628492 on Tuesday November 23, 2021 @12:58PM (#29320906)
I'm new to htmx and alpine, but isn't alpine's global store what you'd want in this case? https://alpinejs.dev/magics/store
Re:Django, HTMX and Alpine.js: Modern websites, JavaScript o... by saimiam on Wednesday November 24, 2021 @03:02AM (#29327835)
(I'm not very familiar with Alpine and htmx but I'm comfortable with Vue and React.)

Htmx pulls html content from the server and replaces inner|outerHTML with it. A JSON object (of the type React/Vue and presumably Alpine use) isn't a good fit to store html blobs and state.