TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Building a single-page app with Htmx

252 pointsby veggieroll7 months ago

26 comments

swyx7 months ago
imo any experienced frontend framework person will be able to pick out the issues with this impl. OP is returning entire strings of HTML (App, Todo, Icon) to rerender on state changes. this works when 1) you dont care about keeping UI state on the parts that are replaced (incl any stateful children of the UI element that happen to be there in your DOM structure), and 2) when you dont have to update the app in any other places when your state changes. go ahead and build your whole app by replacing innerHtml, frontend frameworks will be right here when you get back from speedrunning the last 10 years.<p>in other words, this todo app is just about the most complex of a frontend you can easily* build with htmx, i&#x27;m afraid. try to fix either 1 or 2 and you end up building components and your own little framework.<p>as an exercise to demonstrate, try taking OPs code and adding a count of todos on each All&#x2F;Active&#x2F;Completed tab that should update every time u add&#x2F;edit&#x2F;delete the todos. see how much extra ui code that takes. compare with equivalent [framework of choice] impl (in most it will just involve 1 state update, thats it). this is htmx&#x27;s explosion of complexity that makes it not [ optimized for change ] (<a href="https:&#x2F;&#x2F;overreacted.io&#x2F;optimized-for-change&#x2F;" rel="nofollow">https:&#x2F;&#x2F;overreacted.io&#x2F;optimized-for-change&#x2F;</a>). code that is hard to change eventually calcifies and consumes code that is easy to change if you do not consistently garbage collect (nobody does)<p>i bought the hype too until i tried building something nontrivial in htmx and im afraid the aforementioned islands of interactivity you can build are very very smol islands indeed.<p>happy to revisit my opinion if there are componentlike design patterns in htmx i am not aware of.<p>*emphasis on easily; with enough elbow grease u can do anything ofc. but then you fall out of htmx&#x27;s very narrow [ pit of success ](obligatory codinghorror dot com link)
评论 #41769523 未加载
评论 #41768368 未加载
评论 #41768425 未加载
评论 #41768027 未加载
评论 #41770812 未加载
评论 #41770998 未加载
评论 #41769202 未加载
评论 #41768396 未加载
评论 #41768251 未加载
评论 #41768498 未加载
评论 #41770695 未加载
评论 #41771596 未加载
评论 #41768561 未加载
评论 #41768469 未加载
评论 #41768260 未加载
extr7 months ago
I am a backend&#x2F;ML engineer and tried using HTMX to create a website with:<p>* Search box<p>* Typeahead<p>* Instantly updating search results<p>It was super instructive. In the end, I realized HTMX was probably not the best tool for that job, but it really helped me bridge the gap between &quot;I get in theory why we use JS on the FE&quot; and &quot;Ah, I can see why client side JS is the obvious choice for this&quot;.
评论 #41768311 未加载
评论 #41769009 未加载
rutierut7 months ago
I see a couple of people here bashing on the practicality of this project. That&#x27;s obviously not the point, it&#x27;s an interesting weird use case that&#x27;s more explorative&#x2F;educational than practical. I thought it was an interesting and inspiring read!
davidedicillo7 months ago
FWIW, as a hobbyist developer who never had a chance to learn React, I found HTMX really helpful to make my Flask projects more reactive without adding much complexity.
评论 #41777517 未加载
评论 #41771283 未加载
turtlebits7 months ago
IME, Htmx is best for enriching server side rendered (non-SPA) apps. I&#x27;m having an great time with single file web apps using FastHTML (python).<p>I&#x27;ve rewritten a bunch of my JS framework apps for simplicity and don&#x27;t miss much.
评论 #41769080 未加载
sgt7 months ago
I&#x27;m not sure about this approach but it does look interesting. I think it&#x27;ll work fine.<p>My method is however to use Django and templates to build a regular MPA, and then switch out link changes (between pages) with htmx functionality so there is no browser reload. At least then you&#x27;ll have a webapp that acts mostly like an SPA.<p>Next up, you can add more interactivity using htmx as much as you want (with some kind of Django components, ideally). You can even add VueJS to one of the pages if you want, but full blown SPA frameworks tend to eat into development time, so rather not unless absolutely needed.
leephillips7 months ago
I don’t know if the article describes the best use of HTMX, but when I wanted to experiment with building an interactive physics application on the web that used Julia on the backend, it was a perfect fit. I could design the whole page without any javascript (almost):<p><a href="https:&#x2F;&#x2F;lee-phillips.org&#x2F;pluckit&#x2F;" rel="nofollow">https:&#x2F;&#x2F;lee-phillips.org&#x2F;pluckit&#x2F;</a>
评论 #41771634 未加载
koolala7 months ago
I hope we build Single-page apps with iFrames one day like how the web originally used &lt;frame&gt;. Everyone only talks about iFrames as if their only purpose is cross-origin content and &lt;frame&gt; is forgotten.
评论 #41767988 未加载
评论 #41772207 未加载
uhtred7 months ago
I think 68% of SPAs don&#x27;t need to be SPAs. The end user doesn&#x27;t care if the browser page refreshes if it is quick.
评论 #41770109 未加载
评论 #41771289 未加载
JodieBenitez7 months ago
It&#x27;s already bad enough that too many devs think only in SPA mode, now you&#x27;re trying to use the wrong tool for the wrong solution !<p>Fun experiment though, in the true &quot;hacker&quot; spirit ;-)
altbdoor7 months ago
I made a somewhat similar prototype by mocking XHR instead of service workers, in <a href="https:&#x2F;&#x2F;stackblitz.com&#x2F;edit&#x2F;typescript-h3wfwx?file=index.ts" rel="nofollow">https:&#x2F;&#x2F;stackblitz.com&#x2F;edit&#x2F;typescript-h3wfwx?file=index.ts</a><p>It was fun for a bit to quickly experiment with how htmx works, but I find it difficult to scale in terms of state.
zoezoezoezoe7 months ago
HTMX is an idea that I never understood. HTML over the wire sounds like the most egregious idea I could have ever thought of. If you want a sub par SPA experience just build an SPA with PHP ;), and if you want a real SPA that doesnt have 600 ms of latency when I click a button that for some god forsaken reason calls an api endpoint, use React or Vue or Svelte like we always have. Is it perfect? Trust me, as someone who is trying to build something that delivers an actual SPA experience with SSR without Node.js, it&#x27;s not, but a real SPA is miles better than streaming HTML over the wire.
评论 #41793050 未加载
VagabundoP7 months ago
For my own hobby useage - ie apps I shared with a few people - htmx is a godsend. It lets me focus most of my time in python&#x2F;flask.<p>I do have a slightly more complicated TTRPG live character sheet that I use for a game I run. Its got five users at once and sqlite backend. Its gotten moderately more complicated over the last year and now sports htmx, discord integration, and will soon have SSE for me to push events to their character sheets, like ability point refreshes etc and other fun stuff without them having to refresh the page all the time.<p>I&#x27;m just thankful I don&#x27;t have to dive into JS frameworks and can mostly stay in html, maybe a little hyperscript.
pier257 months ago
I&#x27;m thinking of starting a project with HTMX and islands of interactivity (probably web components). Anyone used this pattern in production?
评论 #41767724 未加载
评论 #41767762 未加载
评论 #41770011 未加载
v3ss0n7 months ago
This is really bad abomination .. please keep SPA to SPA Frameworks and leave HTMX out of it..
BiteCode_dev7 months ago
Which means offline htmx is possible, althought I wouldn&#x27;t love to maintain that.
maddalax7 months ago
imo htmx is good but its a bit too low level to use directly, you sort of have to rebuild all the features frameworks like React have, such as components in your server programming language.<p>I&#x27;m building <a href="https:&#x2F;&#x2F;htmgo.dev" rel="nofollow">https:&#x2F;&#x2F;htmgo.dev</a> to do that with go + htmx, and <a href="http:&#x2F;&#x2F;fastht.ml" rel="nofollow">http:&#x2F;&#x2F;fastht.ml</a> seems like a good contender for python
baggachipz7 months ago
<i>&quot;Your scientists were so preoccupied with whether they could, they didn&#x27;t stop to think if they should&quot;</i><p>At that point, maybe stop fighting with service workers and simply use a framework like Vue. It allows html templates to be swapped in, in much the same way. Except you can actually debug it and store in localStorage if you desire.
评论 #41767986 未加载
Bengalilol7 months ago
I wanted to send a UX feedback : Multiline text shrinks the &#x27;x&#x27; button (the more text, the more shrunk the button gets).
sinanisler7 months ago
it&#x27;s sucks man who even uses this useless thing btw <a href="https:&#x2F;&#x2F;swag.htmx.org&#x2F;products&#x2F;htmx-sucks-mug" rel="nofollow">https:&#x2F;&#x2F;swag.htmx.org&#x2F;products&#x2F;htmx-sucks-mug</a>
synergy207 months ago
seems to me a stretch for what it&#x27;s best for and designed for
pyzn7 months ago
Seems like lots of code for a todo list
davedx7 months ago
Htmx - the hipster tech of the decade, honestly
nsonha7 months ago
&quot;Simple&quot;
tzahifadida7 months ago
Was wondering if any1 embeds react spa apps in golang binaries to build a lean SaaS?
kccqzy7 months ago
Anyone who says React has mired developers in complexity needs to go back ten years and use jQuery to build a single-page app and remind themselves how much less complex React is. I know that because I rewrote a jQuery-based SPA in React back in 2015 and that experience was so revelatory that I will never forget it.<p>It is then that they will realize complexity comes from single-page apps. Pushing back against that complexity should result in not building SPAs, which is where Htmx comes in. There are still plenty of very successful web apps that are not SPAs.<p>If a product owner asks to build a SPA, a developer&#x27;s job is to stop and ask why. Most likely what the product owner really has in mind can be accomplished without a SPA.
评论 #41769515 未加载