For backend developers like me, the frontend ecosystem seems too much bloated, or at least, too much to take if we just want to have a frontend for our small application with a little interactivity on the front. A solution to this, is to simply say no to JS frameworks, and work with hypermedia served from your backend, introducing HTMX.
I have heard about it a while back, but I didn’t give it much attention. I didn’t realize the potential upside of not having to build a JS framework to introduce complexity in my app. Back then, I was working almost exclusively with python and especially Django, which is a framework that combines very well with HTMX. Since most tutorials on Django makes you work with the Django templating engine, to introduce interactivity without JS thanks to HTMX is very much straightforward. But how does it work exactly ?
Basically, the core idea behind HTMX is that your server is going to send a fully rendered component to your client to replace or enrich some part of your HTML. Of course, in practice it is a bit more complex and allow you to do advanced tricks. But in practice, the most important properties are
hx-delete, as they allow you to trigger an HTTP call to get the content which will replace a defined target in your HTML.
HTMX also supports additional attributes like
hx-trigger, which allows you to define the events that trigger the HTTP requests, and
hx-swap, which specifies how the response should be inserted into the page. With these attributes, you have fine-grained control over the behavior of your interactive elements.
There is actually a Django extension called django-htmx to integrate HTMX directly in the python framework, which is one of the nicest combination with the frontend library imho.