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

> I don't think browsers that throw on storage in private browsing allow service worker usage in private browsing either.

Ah, I guess you're right about this. I was mainly thinking of Firefox private browsing, which indeed doesn't allow service workers at all. (Which itself rules out this use case... transient storage like in Chrome is much easier to develop with.)

> Do you expect devices to have more RAM than storage often?

The main reason is restrictive quotas. It's hard to come by authoritative data on the limits, but [this MDN documentation](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Browser_storage_limits_and_eviction_criteria#Storage_limits) says Firefox only guarantees a minimum of 10mb, which is far too small. Maybe the user has filled up all their local storage with photos and videos. The browser could also set the storage quota far below the RAM size, e.g. private browsing mode could arbitrarily set the quota to something like 100mb, perhaps to avoid abuse, mitigate fingerprinting, etc. These details also tend to change over time as well. I'd also add that cleaning up storage so you don't end up leaking quota is trickier as well, especially if there is a chance of ungraceful exits (e.g. tab crashes, OOM), whereas RAM is always freed in these cases.

IIRC Blobs don't have to be written to disk - the browser can opt to keep them in memory (and presumably will if there's no storage space available?)

As noted we also can't guarantee that writing to disk will actually succeed even if there is quota available, since storage errors are surprisingly common. Normally in a SW this isn't too big a deal since in the case of storage failure or cache miss you can fall back to network. However in our case there is no fallback, so in the event of a storage error the fetch fails.

> Conversely trying to keep a large set of data in RAM may also degrade the experience by creating memory pressure, etc.

I don't think keeping data in RAM is as problematic as writing it to storage. Storing 200mb data in memory should be no problem for the vast majority of devices. Writing 200mb to storage could take several seconds on some devices. I think it's more likely that writing to storage will pose a significant negative impact to performance.

-- 
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-747525636

Received on Thursday, 17 December 2020 15:52:33 UTC