Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long time waiting Request to Service Worker

I have noticed that the time waiting for service workers to respond with items from the cache is not as fast as you would expect it to be. I have seen the same wait times with both sw-precache and a custom written service worker.

Request to ServiceWorker

What are the possible causes for this wait time time and how could I reduce it?

My fetch event on the custom service worker looks like:

self.addEventListener('fetch', function(event) {
    event.respondWith(
        caches.match(event.request).then(function(response) {
            if (response) {
                return response;
            }
            return fetch(event.request);
        })
    );
});
like image 480
Kevin Farrugia Avatar asked May 22 '17 06:05

Kevin Farrugia


People also ask

How do I find out if a service worker is running?

A: From a page on the same origin, go to Developer Tools > Application > Service Workers. You can also use chrome://inspect/#service-workers to find all running service workers.

What is an example of a service worker?

Examples of personal service positions include: medical assistants and other healthcare support positions, hairdressers, ushers, and transportation attendants. Examples of cleaning service positions include: cleaners, janitors, and porters.

Is service worker intercepted?

Service Workers are a special type of Web Worker with the ability to intercept, modify, and respond to all network requests using the Fetch API. Service Workers can access the Cache API, and asynchronous client-side data stores, such as IndexedDB , to store resources.


1 Answers

Do you have 'Update on reload' checked within your Chrome Dev Tools under the Application -> Service Worker tab?

If so then I think this may be the problem as it'll be re-running all your Service Worker code, which can be quite a lot of code when using sw-precache, on each reload.

like image 188
chrisdwheatley Avatar answered Sep 27 '22 21:09

chrisdwheatley