-
Hi all, new to htmx and trying to figure out the best way to accomplish the following:
I'm trying to delete an answer then re-render the question. If the POST endpoint returned the HTML, this would be easy to do:
However, since the POST endpoint does not and I need to make a follow up GET request to get the HTML, I'm not sure of the best way to accomplish this. What I'd like to be able to do is something like:
and it would swap in the HTML returned by What's the recommended way to implement something like this? I've managed to get it working by following the idea in Solution 3 here: https://htmx.org/examples/update-other-content/#events, but I don't love this as it requires me modifying my endpoint to include the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
May I ask why? The benefit you get from modifying your backend endpoint is that you would solve the usecase in a single roundtrip to the server. The issue with the setup you're describing here, is that you'll have your client wait for the server answer to then fetch the updated question, wait again for the server answer before updating the UI, when the UI could be updated along the first response. As commonly, the longest delay is the roundtrip to the server, you'd be basically doubling the latency of your user action. From what you're describing, it looks like you're not sending anything in the first response, it'd be a shame to not take advantage of it to return your updated HTML then! (Actually, even if you were, you could then rely on OOB swapping)
I may be missing something there as well, but what's so wrong with having client-type specific code in the backend ? Several common headers allow you to make a backend endpoint that can serve different client formats (both in receiving and answering data), such as Requests made by htmx will all have the If you really want to go with the double roundtrip approach though, Hope this helps |
Beta Was this translation helpful? Give feedback.
May I ask why? The benefit you get from modifying your backend endpoint is that you would solve the usecase in a single roundtrip to the server. The issue with the setup you're describing here, is that you'll have your client wait for the server answer to then fetch the updated question, wait again for the server answer before updating the UI, when the UI could be updated along the first response. As commonly, the longest delay is the roundtrip to the server, you'd be basically doubling the latency of your user action.
From what you're describing, it looks like you're not sending anything in the …