4

I'm writting a progressive webapp and implemented a stale while revalidate strategy to handle some of the requests sent by the application.

Checking the network tab in the devtools, i'm seeing that those requests are correctly marked as served from ServiceWorker. However some of them appeared to be quite long (from 200ms to 500ms), so i checked the timing details and found that most of the time was spent in Request to ServiceWorker

This link tells us that Request to ServiceWorker refers to "The request is being sent to the service worker." But it doesn't tell us much on what is actually occurring during this phase and if there is anything we could do to optimize it.

Searching the web, i didn't found futher details about that (only this previous stackoverflow post describing a similar issue).

Does someone have any details on what is actually going on during this Request to ServiceWorker phase ?

Samuel Maisonneuve
  • 1,025
  • 10
  • 21
  • You are right, "Request to ServiceWorker" refers to the runtime needed to be completed by the service worker e.g. push notifications and background sync. Here are some links that should help you optimize service worker ([High-performance service worker loading](https://developers.google.com/web/fundamentals/primers/service-workers/high-performance-loading) and [HTTP Caching](https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching)). – Mr.Rebot Jul 31 '18 at 23:21
  • Thanks for your comment ! However, it's still not clear to me : what is the link between the 'runtime needed to be completed by the service worker" and "push notifications' or "background sync" ? What do you mean by "runtime needed to be completed" ? Anyway, thanks for sharing :) – Samuel Maisonneuve Aug 01 '18 at 07:49
  • It is the time from start of the request until the promise of that request is finished – Mr.Rebot Aug 01 '18 at 08:40
  • Background sync and push notification are some functions supported in service worker – Mr.Rebot Aug 01 '18 at 08:41

1 Answers1

1

Thanks to @Mr.Rebot and also to chromium guys, i think i get it clear now :

Request to Service Worker is measured inside the service worker thread. It starts when a fetch event is received by the service worker and it ends when e.respondWith resolves (= the HTTP header is available, but the body isn't yet).

Content Download, on the other hand, evaluates the time it takes for the body to be read (= from header available to body has been read)

Samuel Maisonneuve
  • 1,025
  • 10
  • 21