Lurker News

Comments (242) 68 threads

Earlier comments
fractaledmind1 reply#
I cannot believe how simple and elegant this is. Using an iframe as a request/response proxy to enable targeted replacement is just
naasking#
You accidentally the
hanniabu1 reply#
> Not even a backend is required.

> In a nutshell, htmz lets you swap page fragments with HTML from the server using vanilla HTML code.
So a backend is needed....

Kalabasa1 reply#
Oops, it's just a mistake on word choice in the nutshell summary. This works on static files like on a local filesystem (in that case the "server" is the local filesystem that serves me files that happen to be html)

Edit: on second thought, direct filesystem access has different origins which would mess with iframes. I'm not on the computer now to test. But at the very least you need a basic web server that serves files.

hanniabu1 reply#
Thanks for the clarification, so it would work the same as a static site where you just need a place to retrieve the files from
turnsout#
Yes, aka a webserver
moritzwarhier3 replies#
It's a fun one liner, but what is the use case?

When I want to replace some element using JS as the user clicks a link, it is progressive enhancement.
Usually links enable history navigation. If you do stuff like this, you need to code it in a way that uses the history API to fix it for users with JS enabled (majority of users).
If you don't want history navigation and URLs, why do you use links?
This breaks history navigation and bfcache for no good reason, or am I missing something? bfcache already provides SPA-like speed, or even better.
No need to avoid regular links if you e.g. link from a list to a detail page.
Also:
> No preventDefaults. No hidden layers. Real DOM, real interactions. No VDOM, no click listeners. No AJAX, no fetch. No reinventing browsers.
So many words saying nothing, just to cater to some sentiment. fetch is part of browsers by the way.
If I need to replace an element as the user clicks a link, I can code it myself (without using this abstraction layer, however thin it is). I also don't need an iframe for doing this. And preventDefault is aptly named and a good reminder for what progressive enhancement should do. If it's not meant to be a link, don't use a link.
And if you want to react to clicks, you know, use click listeners (event handlers). Where's the problem?
It is understandable to developers and uses native browser functionality as intended. As opposed to this hack, which I'd find pretty glaring, bug-prone and hard to understand, would I have to debug an issue on some page that uses this snippet.
To me this seems like useless indirection and technical debt. If you really need low-code AJAX "links" (who says you need that, if you don't want an SPA?), code yourself some understandable JS that is properly tailored to your site and respects history navigation, or use a library that is a good fit for your concrete use case.
As a joke, I like it though…

scwoodal1 reply#
The use case is a fun one liner.
moritzwarhier1 reply#
As a fun hack / code golf it's great. I was being tonedeaf I guess, woosh as they say.

The marketing pitch on the landing page is written so well that I took it too seriously probably.
I know htmx but wasn't able to see this as a parody, so my fun capabilities were failing :)

Kalabasa1 reply#
I have changed it to explicitly state within the first paragraphs that "htmz is an experiment" now. I started this as a joke but turned into a fun working solution - I myself am not sure if this is just a joke or a thing. Maybe I'll use it in some smaller projects, or maybe not!

Continue this thread — 1 reply

oneshtein1 reply#
It can be used in Markdown with HTML enabled but JavaScript disabled.
moritzwarhier#
Haha I hope not ^^
sesm#
The use case is to show that you can do core htmx functionality in a one-liner.
tommica#
Can it trigger JS returned from the proxy? Something like

Load more comments