W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2015

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

From: Ying Le Jia <jiayingl@cn.ibm.com>
Date: Wed, 9 Dec 2015 17:25:21 +0800
To: public-webapps@w3.org
Message-Id: <OF0A1D07C6.E32BBC92-ON48257F16.0030D6FB-48257F16.003433C5@notes.scniris.com>
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 
recommendations?

Thanks,

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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:14:58 UTC