Re: [w3c/ServiceWorker] provide a way to execute work after browser has consumed a response (#1397)

> respondWith is calling waitUntil under the hood so that waitUntil for fetch events is probably not used much.

I don't think the statement "waitUntil for fetch events is probably not used much" is necessarily true.  The sites I have looked at lately do use FetchEvent.waitUntil() for things that may last beyond the respondWith() resolution.

I agree that waitUntil is a repeated issue that needs educating people, but I don't think we should give up on the extensible web and stop exposing primitives in favor of wrappers because of it.  I feel pretty strongly we should expose the attribute promise even if we also expose a wrapper helper.

Would people be ok with both `FetchEvent.responded` and `FetchEvent.afterResponse()`?

> Also, the tasks done in doCompletionWork are probably often fast. 

I think this has been our assumption, but I've seen tracing that says there is a small significant drag from even simple code (at least in chrome).  For example, a function that recorded timing measurements in a js object and then issued a fetch() to log the result to the server added a 5ms to 10ms drag on FetchEvents.  Looking at the completion work code you would not expect it to really be noticeable, but it was.

Also, this code can be a further drag right after the worker thread starts up and the js jit is cold, etc.  That often means the navigation FetchEvent is going to be the slowest which is one we really care about.

> Is it useful for doCompletionWork to access the response given to respondWith?

I think we could have the responded promise resolve with the consumed Response.  If they want an unconsumed Response the SW script would have to do their own clone() and pass the duplicate into their completion work handler via a closure.

> Is the work done by doCompletionWork the same if respondWith is called or not?

I think it would be useful for the promise to resolve whether a promise settles with a promise to respondWith() or respondWith() is not called triggering fallback.  Of course whether those are treated the same by the site is up to how they write their script.

> Should doCompletionWork be called only if respondWith is called?

I think it should be called for fallback cases as well.  If sites don't want that they can avoid registering their completion work in those cases.

-- 
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/1397#issuecomment-479488845

Received on Wednesday, 3 April 2019 13:28:19 UTC