Solution 3 gave me a good laugh though.
Solution 3 gave me a good laugh though.
This is a complete non-issue in unpoly as you can have multiple targets:
<a href="/posts/5" up-target=".content, .unread-count">Read post</a>
https://unpoly.com/targeting-fragmentsHTMX gets a lot of attention, but I think it's not the best option in its field.
I've done tabbed UIs that worked like HTMX. But instead of trying to do div surgery it replaced the entire tab. It was like 20 lines of JS and a few lines in Rails to render without a layout based on a URL query param.
When we're talking dozens of KBs of HTML for a tab it's not the extra complexity to try and slim that down.
Of course the downside is everything must go to the server. While not perfect, many spa also do not work nicely without a connection, although they could.
Another thing is that the templates can get a bit crazy quick.
I found a good solution is to use swap-oop (https://htmx.org/attributes/hx-swap-oob/) for everything and have a "component" wrapper server-side to abstract the ids and which template to choose.
Then, some kind of typed data structure tracking all the element ids, since you need to refer to them from the templates to know which element to update. This way you can easily find all the templates that update a specific id or all the ids that are updated by a template.
Right, which you can achieve by replacing the main content div. HTMX takes it many steps further and allows you to slice the HTML up into small bits and replace only those. This adds a lot of complexity for little benefit.
Also, no compilation step, so no need for npm, etc
const $ = document.querySelector.bind(document)
const $$ = document.querySelectorAll.bind(document)https://api.jquery.com/category/ajax/
Have you seriously looked at this and thought "yeah thats better than using a single native function (fetch)"?
As for the rest of the API - what would you even use besides the css and selector functions? Which again, the native `classList` and a simple bind to the selectors are simpler and less verbose.
$(this).closest(".cont")
for example, is pretty nice in jquery.