Skip to content

Commit

Permalink
Cleanup service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharsadhwani committed Apr 14, 2021
1 parent 190960e commit 2078a6a
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions web/serviceWorker.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
const appName = 'recv-app'
const assets = ['/', '/index.html', '/style.css']
self.addEventListener('install', installEvent => {
installEvent.waitUntil(
caches.open(appName).then(cache => {
cache.addAll(assets)
}),
)

self.addEventListener('install', event => {
event.waitUntil(caches.open(appName).then(cache => cache.addAll(assets)))
})

self.addEventListener('fetch', event => {
event.respondWith(
fetch(event.request)
.then(response => {
return caches.open(appName).then(cache => {
cache.put(event.request, response.clone())
(async () => {
try {
const response = await fetch(event.request)
const cache = await caches.open(appName)
cache.put(event.request, response.clone())
return response
} catch (error) {
const cache = await caches.open(appName)
const response = await cache.match(event.request)
if (response != null) {
return response
})
})
.catch(error => {
return caches.open(appName).then(cache => {
return cache.match(event.request).then(response => {
if (response != null) {
return response
}
throw error
})
})
}),
}
throw error
}
})(),
)
})

0 comments on commit 2078a6a

Please sign in to comment.