DEV Community

Saad Saif
Saad Saif

Posted on

PWA empty fetch callback

If you have the empty fetch call back in service worker, PWA will no longer be installable from august 2021.

You have to respond with custom response in fetch request, check if request is in cache then send file from cache else proceed with request

self.addEventListener('fetch', (evt) => {
  evt.respondWith(
    caches.match(evt.request).then((cacheRes) => {
      return cacheRes || fetch(evt.request)
    })
  )
})
Enter fullscreen mode Exit fullscreen mode

Top comments (0)