I want to create a SharedWorker but i want to keep the state alive when navigating away from a page to another or just simple reloading the page. I don't want to create a SPA or do anything with service worker to keep the state alive. I just want to use SharedWorker...
But whenever I attempted to reload the page the SharedWorker also gets reloaded. which i don't want.
The best Q/A i could find was this post Do Shared Web Workers persist across a single page reload, link navigation
however that is really outdated i think. Cuz i also found this in the spec:
NOTE: The second part of this definition allows a shared worker to survive for a short time while a page is loading, in case that page is going to contact the shared worker again. This can be used by user agents as a way to avoid the cost of restarting a shared worker used by a site when the user is navigating from page to page within that site.
However my attempt at doing so resulted in: SharedWorker was reloaded when page reloaded. even tried a clicking a link that linked back to itself.
my attempt where to create a date and post a message back to any connector and display the time when it was first created it's updated every time.
note: i did not have any other tab open...
Do you know of any hack to keep it alive? i have tried transfering the SharedWorker.port to another iframe, popup and even a service worker and set it up so it instead listened to all the messages in another thread. and the sharedWorker had a interval where it posted a message of creation date and a sequence id that increased with each post
But whenever the tab that created the SharedWorker was destroyed or reloaded the other popup (that dose not construct a SharedWorker by itself) stop receiving messages
Do you know of any workaround to keep the shared worker alive durning reload?