Why service worker is even slower than normal network request on chrome

Viewed 20

I used service worker to precache a 15KB size page, but why serving it can even be slower than normal network requests? Sometimes the cache served from service worker can take ~200ms and sometimes can take ~600ms which may be even slower than network requests.

The service worker logic is pretty easy. It does an url match then use fetchEvent.respondWith to return the response.

It seems the problem is not related with Cache API. I tried to cache the page as a in-memory state in the service worker, in the case I guarantee that the state is not destroyed, the same size response served from service worker can still take 150ms~600ms

I tested it in chrome. It seems Safari has a comparatively better performance.

0 Answers
Related