Re: [w3c/ServiceWorker] Proposal: pass custom params in ServiceWorkerRegistration for future use (#1157)

@laukstein you need to compare like-for-like here. In your proposal the browser is doing the work for you, but that doesn't mean it takes 0ms.

> [indexeddb] will require addition async call before get to ServiceWorker events.

Right, but in your proposal `self.registration.customParamFoo` needs to be provided synchronously, whether the developer wants it or not. That doesn't seem better, it recreates the problems of localstorage.

> I trim queries from URLs by server-side to avoid duplicate content, and cache/serve files without queries

This isn't a browser problem, it's a problem you're creating yourself.

> The long query can exceed the limit supported by server and browser.

Whooaaaa how much data are you needing to pass in? If it's that much, the synchronous deserialising of that data is likely to be slooowww.

> Array as string in URL after will be needed to be converted to array, what if passing Date in URL, multiple level Object (JSON) as string, etc.

Right, but in your solution the data needs to be structured-clonable and deserialised per service worker startup. Just because the browser is doing it for you, doesn't make it free.

For comparison's sake, here's what I'm proposing (using [idb-keyval](https://www.npmjs.com/package/idb-keyval)), which works today:

In your page:

```js
async function registerSw() {
  await idbKeyval.set('urlsToCache', ['/', '/cat.gif']);
  return navigator.serviceWorker.register('/sw.js');
}
```

In your service worker:

```js
addEventListener('install', event => {
  event.waitUntil(async function() {
    const [cache, urls] = await Promise.all([
      caches.open('static-v1'),
      idbKeyval.set('urlsToCache')
    ]);
    await cache.addAll(urls);
  }());
});
```

-- 
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/1157#issuecomment-306469745

Received on Tuesday, 6 June 2017 12:24:13 UTC