[service-workers] How can one use in-memory global state in Service Workers?

Experts on Service Workers:

Per the spec (
https://slightlyoff.github.io/ServiceWorker/spec/service_worker/), global 
states will be discarded in between service worker restarts. This is 
understandable, however, it makes it impossible or too difficult to 
implement some use cases.

Consider applications like e-business client, email client, chat client, 
collaborative document editor, etc. Those applications need to be able to 
support multiple user accounts (one active at a time), each having a 
separate IndexedDB database, and a dedicated secret key for data 
encryption/decryption. When handling requests, Service Workers need to 
know the current user ID and secret key - needless to say, we cannot 
persist the user's ID and secret key on disk for security reasons.

More specifically, what we need to do in the Service Worker:
1. The Service Worker receives a URL request;
2. The Service Worker looks up the requested resource in the IndexedDB 
database identified by the user ID;
3. The Service Worker uses the user's secret key to decrypt the resource;
4. The resource is returned to the client;

With SharedWorker, we can maintain in-memory global state across pages. 
However, there does not seem to be a direct way to access SharedWorker in 
Service Workers. Is there a solution for this? What are the 


Ying Le Jia (ӭ)
Senior Software Engineer, IBM Notes and IBM Verse
IBM China Software Development Lab (CSDL), Beijing

Tel: 86-10-82453472
E-mail: jiayingl@cn.ibm.com

Received on Wednesday, 9 December 2015 14:52:40 UTC