GoogleChrome / samples

A repo containing samples tied to new functionality in each release of Google Chrome.
https://www.chromestatus.com/samples
Apache License 2.0
5.77k stars 2.38k forks source link

SW Sample: storing data #85

Open owencm opened 9 years ago

owencm commented 9 years ago

I have a session token in my page that I want to use in my SW.

I'm using postMessage to send it to the SW and then plan on using IDB to store it there.

A small sample that stores bits of (non-response) data persistently would be pretty nice, imho.

jeffposnick commented 9 years ago

FWIW, https://github.com/GoogleChrome/samples/blob/gh-pages/service-worker/offline-analytics/service-worker.js shows off storing failed Google Analytics requests using IndexedDB.

We could put together a more generic sample if you think that's useful. I'd imagine the controlled page could just write directly to IndexedDB and the service worker could read from it instead of having to use postMessage(), though.

owencm commented 9 years ago

I think this is a common enough need that having a small sample for storing and reading data on both sides would be neat. I imagine most apps need it, especially if they - like me - need to do authenticated network requests with tokens both from the page and from the SW.

Plus, trying to get up and running with IDB just to store one session token is a real annoyance right now.