← Back to context

Comment by yawaramin

1 day ago

That's incorrect. Htmx actually works really well with progressive enhancement, thanks to hx-boost. See https://dev.to/yawaramin/why-hx-boost-is-actually-the-most-i...

If you stick to GET and POST requests, you can ensure your app works almost exactly the same with or without JavaScript.

Thanks for pointing out a mitigation. I'm confused though. How does "htmx sends a request header HX-Request: true with every request." happen without javascript? And does this imply you need a backend server that understands whatever this header is for the graceful fallback? Ie, it wouldn't work with just nginx...

  • > How does "htmx sends a request header HX-Request: true with every request." happen without javascript?

    It doesn't. If JavaScript is disabled, this header is not sent.

    > you need a backend server that understands whatever this header is for the graceful fallback

    Yes, as I mentioned in my blog post linked earlier: 'the backend server can use a fairly simple heuristic to figure out that it should respond with a fragment:...The request has a header HX-Request...The request does not have a header HX-History-Restore-Request...If these two conditions are fulfilled, it can respond with a fragment. Otherwise, it can respond with a full page ie <!DOCTYPE html>... and so on.'

    > it wouldn't work with just nginx...

    It would in a limited sense if you design the pages in a certain way and use the `hx-select` attribute: https://htmx.org/attributes/hx-select/

    But...htmx is not really meant to work with just Nginx or other static web servers, it is meant to work with a BFF (backend-for-frontend) that specifically knows how to serve and handle the app in question.

    From the criteria you have mentioned so far:

    - Works without JavaScript

    - Works with a static web server like Nginx

    I can only conclude that you are talking about serving static sites with no dynamic interactivity. That's not really what htmx is about. Htmx is more like a simplified way to do SPA-like things.

    • > Htmx is more like a simplified way to do SPA-like things.

      Okay. Then we agree. "Htmx is power tools for using Javascript to alter HTML".

      With the implicit premise of starting from javascript you see that as "Power Tools for HTML". Without this premise I see it as "Power Tools for Javascript".

      I think this distinction is not only important because I question the premise, but because many people who've talked to me about Htmx are confused about what Htmx is and believe that it works without javascript. This is not Htmx's fault, of course, but it could be made clearer by avoiding easily misinterpreted headlines like this.

      1 reply →