htmx interview question · Most asked
How would you implement active search with htmx?
Summary
A search input with hx-get to the search endpoint, hx-trigger="input changed delay:300ms, search", hx-target on the results container (for example the tbody), hx-sync="this:replace", an indicator, and hx-replace-url to keep the query in the URL. The server returns only the matching rows (or an empty-state row).
Longer Answer
On the server it's a parameterised query with a LIMIT. The same URL should return the full page for normal visits (check HX-Request) so the search URL can be bookmarked. aria-live on the results helps screen-reader users.
Key Points
- Debounced trigger + changed.
- Swap only the results.
- hx-sync replace to avoid stale results.
- hx-replace-url and full-page fallback.
Deep dive: htmx Tutorial: Active Search
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?