[w3c/ServiceWorker] Detecting service worker termination (#1550)

Is there a way to detect when a service worker is about to be suspended/terminated when it's not needed?
Browsers aggressively terminate service workers, in order to save resources. 

But what if I wanted to do some computations based on the requests done by the web pages?
I'd like to perform some bookkeeping and save this to IndexedDB. However, at the moment I'm forced to write my computations for every single request to the database. I'd like to batch these writes, in one big write just before the service worker is about to be suspended. 

I envision it could be interesting to perform some minor work, such as saving these kinds of computations to the database, by introducing a `beforeTerminate` event. This could be a very limited event in which only small amounts of work would be allowed and after which the service worker would be immediately terminated.

Does anyone have any thoughts on this or is there another way to accomplish this?

-- 
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/1550

Received on Wednesday, 28 October 2020 17:27:11 UTC