TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Wasm-service: Htmx, WebAssembly, Rust, ServiceWorker proof of concept

216 点作者 richardanaya超过 2 年前

15 条评论

chrismorgan超过 2 年前
The demo also demonstrates why something like this is insufficient: you can’t rely on the service worker loading. Service workers <i>must</i> be optional. There’s a reason invocations always start by checking if navigator.serviceWorker even exists, and why navigator.serviceWorker.register() returns a Promise, and why the ServiceWorkerRegistration type is comparatively complicated: service workers aren’t permitted in all contexts, and even when they are, they’re installed asynchronously in the background after the page finishes loading.<p>To show this easily, try this in a Firefox Private Browsing window: service workers are disabled there, so the request goes through to the server, which responds 405 Method Not Allowed.<p>So in order to make this approach reliable, you’ll need to run that code on your server, not just in the service worker. This is totally viable, but an approach that has seen surprisingly little experimentation. (I myself have a grand scheme that’s actually fairly fleshed out, but I’ve only touched it once in the last year and a half, so don’t hold your breath. My scheme is predicated upon aggressively not <i>requiring</i> client-side scripting, but using it only for completely optional enhancement; and upon running the same source code in a worker, in a service worker, at the edge or on the origin server, with only a teeny bit of JavaScript on the main thread.)
评论 #33229521 未加载
评论 #33230992 未加载
评论 #33319875 未加载
评论 #33229915 未加载
评论 #33230708 未加载
评论 #33229415 未加载
Gunax超过 2 年前
Not sure i really get it.<p>So we used to have react&#x2F;vue&#x2F;whatever. You click button, and the front end computes the new DOM. No server needed.<p>Then, we decide to use htmx, where the server actually computes the new DOM elements, and the client is just a dumb client that displays whatever the server gives.<p>And now, we give the users browser all of the information to act like a server, intercept the call, and compute what the server would have responded with (saving since network packets and lag).<p>Did I understand that correctly?<p>And yea, I also saw that talk about HTMX on HN yesterday... didn&#x27;t really understand the advantage then either.
评论 #33233308 未加载
评论 #33320487 未加载
评论 #33231991 未加载
bkolobara超过 2 年前
What a coincidence, I was just discussing on discord a similar approach for our Rust web framework submillisecond[0].<p>Submillisecond uses lunatic to run Rust code compiled to WebAssembly on the backend. We are working on a LiveView-like library now. And one thing I would love to give developers for free is an offline-first experience. You write everything in Rust, compile it to WebAssembly, run it as a regular backend on lunatic, but also allow for moving the whole server into the browser for a offline experience. If SQLite is used for the DB, it could also potentially run in the browser.<p>This doesn&#x27;t need to move the whole app into the browser, but could do so just for more latency sensitive workloads that don&#x27;t fit LiveView well. Like form validation on every keypress, etc.<p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;lunatic-solutions&#x2F;submillisecond" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lunatic-solutions&#x2F;submillisecond</a>
评论 #33320552 未加载
richardanaya超过 2 年前
Saw HTMX on hacker news the other day, thought I’d do this interesting experiment.
评论 #33231171 未加载
评论 #33229341 未加载
评论 #33229806 未加载
评论 #33230946 未加载
girvo超过 2 年前
While this is the least important part of this project: Htmx is great! I&#x27;ve used it quite extensively lately for internal tools at work. AlpineJS has also been useful for things that need a little more JSON-API-driven oomph.
评论 #33231911 未加载
transfire超过 2 年前
Interesting. So a front end could utilize HTMX to do dynamic client side rendering <i>without javascript</i>, limiting what goes server-side to only the things the server needs. Sounds very promising.<p>The code looks a bit complicated though. Some explanation of what’s going on would be helpful.
评论 #33229376 未加载
评论 #33229987 未加载
aitchnyu超过 2 年前
I was actually wondering when fake service worker servers would take web dev by storm and become the preferred way for offline-first web apps. Go to &#x2F;take-census-with-spotty-connection, a &quot;web app&quot; bundled into a service worker gives a form, submit it and the web app saves it into in-browser database. I imagined it as a pure js solution though.<p>After a Django+React project demanded 24 hour days from my team, I achieved the insight that with pure Django pages, you call (request) using strings containing function name and parameters like `&#x2F;articles&#x2F;page&#x2F;2` and get an output (response) and the runtime (browser) can memoize (cache) the result since the whole process is... functional. Some of my react pages had a dozen ways of reaching illegal states, many caused by network calls. The former became the ideal to strive for. Hence why I think fake web servers via service workers will be popular for bug free (heh) offline first apps.
评论 #33322089 未加载
hardwaregeek超过 2 年前
Haha this is fantastic! Turn something that is insistently server side into something client side. Plus it&#x27;s using cool tech.
harryvederci超过 2 年前
Is using a ServiceWorker required here? I&#x27;m not familiar with them yet, maybe someone can explain if the same can be achieved with htmx its `beforeRequest` event (<a href="https:&#x2F;&#x2F;htmx.org&#x2F;events&#x2F;#htmx:beforeRequest" rel="nofollow">https:&#x2F;&#x2F;htmx.org&#x2F;events&#x2F;#htmx:beforeRequest</a>), and cancelling the request after running the wasm code?<p>I was considering using htmx + wasm for my website. Combined with my one-sqlite-db-per-user infrastructure it may enable me to do some fancy edge computing :)<p>Glad to see a PoC showing that the htmx + webassembly part of it is possible!
logankeenan超过 2 年前
I’ve done similar experiments compiling a Rust server to WASM and running it in the browser. I didn’t use HTMX, but it could easily be added.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;logankeenan&#x2F;notes-demo-spa" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;logankeenan&#x2F;notes-demo-spa</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;logankeenan&#x2F;axum-browser" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;logankeenan&#x2F;axum-browser</a>
gedw99超过 2 年前
This is clever.<p>Can we render on server , then upgrade to render on client progressively?<p>Also can we load other wasm using server push in the background . You get runtime plugins then
padjo超过 2 年前
Now that we’re heading back to dumping html over the wire I look forward to the reinvigoration of the XSS attack.
RamblingCTO超过 2 年前
I didn&#x27;t read the article (I know, I know), but I think it would be really cool to get to run other languages in the frontend. Javascript just plain sucks. Having something like Kotlin or golang (in a reduced form) would be really neat and could professionalize the frontend even more. I think the frontend is always a bit wild west, compared to most backend implementations. That&#x27;s not only due to more testing but also stronger language guarantees.
评论 #33234265 未加载
评论 #33235971 未加载
评论 #33234604 未加载
altilunium超过 2 年前
Which is faster, v8 javascript or webassembly + rust?
diego_moita超过 2 年前
So, for your webpage to start it has first to download a 1.74Mb component?<p>Just because &quot;it is cool&quot;?
评论 #33229711 未加载
评论 #33230182 未加载
评论 #33230310 未加载
评论 #33322191 未加载
评论 #33229659 未加载