Re: [w3c/ServiceWorker] Make Service Worker control only specific pages (#985)

@inian you can't call `respondWith` asynchronously. It'd need to be more like:

```js
const pagesToControl = ["/page1.html", "/page2.html"];

self.addEventListener("fetch", function(e) {
  e.respondWith((function() {
    if (!e.clientId) return fetch(e.request);
    return clients.get(e.clientId).then(client => {
      const clientURL = new URL(client.url);

      if (!pagesToControl.includes(clientURL.pathname)) {
        return fetch(e.request);
      }

      // respond to fetch request
    });
  }()));
});
```

-- 
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/985#issuecomment-253781993

Received on Friday, 14 October 2016 12:06:02 UTC