Re: [slightlyoff/ServiceWorker] Inconsistencies due to when clients are created (#870)

> That seems like an unfortunate setup since in general fetch doesn't need to know about this, only for navigation.

@annevk, to avoid that concern, we might want to invoke match the service worker registration twice: one for fetching the main resource in Handle Fetch and the other for setting a controller to the client's global. I outlined the simplified flow below:

```
// Window client matching
Navigate(request)

  Process a navigate fetch(request)

    Fetch(request)

      response = Handle Fetch(request)

        reg = Match Service Worker Registration(request.url)

        Dispatch the FetchEvent at reg's active worker

          // Use e.clientId, e.reservedClientId, e.targetClientId

      Process a navigate response(request, response)

        Load an HTML document

          Create a Document

          Initialize a new Document object

            Create a Window

            reg = Match Service Worker Registration(request.url or Document's URL?)
              // Are request.url and Document's URL always the same at this point?

            Set the Window object's active worker to reg's active worker

            Create an environment settings object
```

```
// Worker client matching
Run a worker

  Create a Dedicated/SharedWorkerGlobalScope

  Create a new environment settings object

  Fetch script

    response = Handle Fetch(request)

    reg = Match Service Worker Registration(request.url)

    Dispatch the FetchEvent at reg's active worker

      // Use e.clientId, e.reservedClientId, e.targetClientId

  (Before step 10) reg = Match Service Worker Registration(request.url)

  Set worker global's active worker to reg's active worker
```

There's still a possibility that the active worker of the registration can be changed from the first matching attempt and the second matching attempt. That is, in that occasion, the main resource and its subresources are served by two different service worker versions. @jakearchibald, I'd like to clarify if this would be okay.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/870#issuecomment-241341776

Received on Monday, 22 August 2016 08:11:22 UTC