7 ms·
just use a service worker to share state, you would be much better off doing this anyways. saves a ton and is performant.
by ravxx 3y ago
just use a service worker to share state, you would be much better off doing this anyways. saves a ton and is performant.
- simonw 3y agoI think you need a SharedWorker for that rather than a service worker https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker https://developer.mozilla.org/en-US/docs/Web/API/SharedWorke...
- jedschmidt 3y agoA service worker would work fine; the connection would be instantiated from the SW and each window/worker could communicate with it via navigator.serviceWorker.
- esprehn 3y agoThat doesn't work because browsers have duration limits on ServiceWorkers: https://github.com/w3c/ServiceWorker/issues/980#issuecomment-782094985 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 https://issues.chromium.org/issues/40284712 Hopefully Chrome will fix this eventually, it really makes it hard to build performant MPAs.
- jedschmidt 3y agoIn my experience, as long as a controlled window is communicating with the SW, the connection will remain alive.
- nchmy 3y agoShared workers (inexplicably) dont exist on Android Chrome https://issues.chromium.org/issues/40290702 https://issues.chromium.org/issues/40290702