News for hackers. Stuff that matters.
Re:Htmx, WebAssembly, Rust, ServiceWorker Proof of Concept by nabakin on Monday October 17, 2022 @12:49AM (#33229915)
I'm more optimistic about using Service Workers in this way, but I agree this was definitely not their intended use case so there will be problems.

There's another flaw I see with using Service Workers in this way. After a period of time where the Service Worker is inactive (a minute or so on Firefox), the browser will shutdown the Service Worker. When it shuts down, all variables in the Service Worker scope are freed and I assume the WebAssembly server instance as well. How would you maintain server state, in this scenario?

Re:Htmx, WebAssembly, Rust, ServiceWorker Proof of Concept by madsbuch on Monday October 17, 2022 @07:33AM (#33232155)
Commit to a browser persistent storage or skip it off to a server.
Re:Htmx, WebAssembly, Rust, ServiceWorker Proof of Concept by nabakin on Monday October 17, 2022 @11:58AM (#33235401)
That's what I'm thinking too. There's no way to keep the state in Rust which means constantly updating a browser persistent storage through JS or keeping state client side in the tab's environment. A pretty janky workaround
Re:Htmx, WebAssembly, Rust, ServiceWorker Proof of Concept by nymanjon on Monday October 24, 2022 @02:18PM (#33320320)
I pretty much build my personal offline-first web apps this way, but with JS.

https://news.ycombinator.com/item?id=33319875

Re:Htmx, WebAssembly, Rust, ServiceWorker Proof of Concept by nabakin on Tuesday October 25, 2022 @11:45PM (#33339581)
Cool! If I'm reading your code correctly, you store service worker state in the cache?
Re:Htmx, WebAssembly, Rust, ServiceWorker Proof of Concept by nymanjon on Wednesday October 26, 2022 @06:55PM (#33350719)
Yeah, I store everything in IndexedDB using a simple Key-Value abstraction library. I have a cache where I store any temporary state between pages.