Re: [w3c/ServiceWorker] [Feature request] Allow keeping service worker alive (#1558)

I think storing the map to disk is the right solution.  The Cache API may be better than IDB, depending on how you are using the blobs.

Responding to a couple of concerns about storage:

> We could be serving a large amount of local content, corresponding to an entire game. The user may not have enough storage quota to save the whole map.

Do you expect devices to have more RAM than storage often?  Or is it that some browsers set very restrictive quotas?

In addition, blobs in many browsers end up getting stored on disk anyway in temporary files.  Moving these to a storage API would not result in a net increase in disk usage.  It may shift around in quota accounting, though.

> In some browsers with private browsing, or certain privacy settings, storage APIs throw on any attempt to use them and so cannot be used at all in these modes.

I don't think browsers that throw on storage in private browsing allow service worker usage in private browsing either.  This is because creating a service worker registration is basically a storage operation itself.  Do you have an example of this?

> Writing all this data to storage could be slow, degrading the user experience.

Conversely trying to keep a large set of data in RAM may also degrade the experience by creating memory pressure, etc.  It kind of depends.  You could balance between the two by having an in-memory cache of responses in the SW if you want to.  It would help until the SW is killed and would naturally repopulate when its woken up and requests start flowing again.

Some other thoughts:

* If your client makes frequent network requests then the SW will be kept alive longer naturally.
* You can also simulate keeping the SW alive from your client by sending it periodic postMessage() ping messages; e.g. once every couple minutes, etc.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1558#issuecomment-747477874

Received on Thursday, 17 December 2020 14:40:24 UTC