htmx interview question · Most asked
How do you organise server templates for an htmx app?
Summary
Put each fragment htmx requests in its own partial template (or use template fragments to render a named block), include it from the full page, and pick partial vs page based on HX-Request. Keep handlers thin and markup in one place.
Longer Answer
Libraries help: django-htmx (request.htmx), django-template-partials, jinja2-fragments, htmx helpers for Laravel, Rails and ASP.NET. Avoid duplicating markup between the page template and the htmx handler; it drifts. Test endpoints both with and without the HX-Request header.
Key Points
- Partials or template fragments.
- One source of markup.
- Branch on HX-Request.
- Test both response types.
Deep dive: htmx: Build Interactive Web Apps with HTML: Organising the Server: Partials, Fragments and Headers
More most-asked htmx questions
- How do you handle form validation errors with htmx?
- How does htmx compare with React or Vue?
- What is htmx?
- What do hx-get, hx-post, hx-put, hx-patch and hx-delete do, and how are values sent?
- What is hx-target, and what relative selectors does it support?
- What swap styles does hx-swap support?
- How does hx-trigger work? Give examples of modifiers and special triggers.
- What security risks are specific to htmx, and how do you mitigate them?