Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Is this actually a reasonable scenario for using HTMX? Is JavaScript even required?


HTMX is basically a JavaScript framework that makes the traditional request-response approach feels like an SPA via replacing only part(s) of the current page with the response. In this case: it loads a small form, submits it to the backend, then replaces the respective part of the page with the updated markup. The state is kept only at the backend.

With some constraints you can create a page that works with or without JS. The same endpoint can be used for serving HTML fragments for HTMX and full page for JS-disabled clients since the HTMX request can be detected by the HX-Request header.


> ...basically a JavaScript framework that makes the traditional request-response approach feels like an SPA via replacing only part(s) of the current page with the response.

Didn't that used to be called AJAX or REST or something?


Yes! HTMX is a better API on top of a XMLHttpRequest for this approach. A hypothetical next iteration of the HTML standard could make most of HTMX unnecessary. Maybe one day.


Answering my own question, you can make an element appear using just CSS and a hash:

https://enmascript.com/articles/2019/09/26/toggle-content-on...

I don’t like messing with the URL to achieve this, so unless using the “details” element, maybe JavaScript is actually the best approach…




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: