Re:WebSockets vs. Server-Sent-Events vs. Long-Polling vs. We...
by simonw on Monday March 18, 2024 @02:01PM
(#39747739)
I think you need a SharedWorker for that rather than a service worker https://developer.mozilla.org/en-US/docs/Web/API/SharedWorke...
[ Parent
| on HN ]
Re:WebSockets vs. Server-Sent-Events vs. Long-Polling vs. We...
by jedschmidt on Monday March 18, 2024 @10:11PM
(#39752305)
A service worker would work fine; the connection would be instantiated from the SW and each window/worker could communicate with it via navigator.serviceWorker.
Re:WebSockets vs. Server-Sent-Events vs. Long-Polling vs. We...
by esprehn on Tuesday March 19, 2024 @12:45AM
(#39753021)
That doesn't work because browsers have duration limits on ServiceWorkers:
https://github.com/w3c/ServiceWorker/issues/980#issuecomment...
Also unfortunately Chrome doesn't keep SharedWorker alive after a navigation (Firefox and Safari do):
https://issues.chromium.org/issues/40284712
Hopefully Chrome will fix this eventually, it really makes it hard to build performant MPAs.
Re:WebSockets vs. Server-Sent-Events vs. Long-Polling vs. We...
by jedschmidt on Tuesday March 19, 2024 @07:07AM
(#39754571)
In my experience, as long as a controlled window is communicating with the SW, the connection will remain alive.