Disable caching when developing
This commit is contained in:
parent
f37ebc1c41
commit
12b629756f
1 changed files with 11 additions and 7 deletions
|
|
@ -53,18 +53,18 @@ async function fetchAsset(event) {
|
|||
// -----------------------------------------------
|
||||
// This page is precached - return it immediately.
|
||||
// -----------------------------------------------
|
||||
//console.log('From cache', event.request.url)
|
||||
console.debug('From cache', event.request.url)
|
||||
return match
|
||||
} else {
|
||||
// ---------------------------------------------------------------
|
||||
// Not in cache - send it for an online request/browser cache hit.
|
||||
// ---------------------------------------------------------------
|
||||
console.log('From network', event.request.url)
|
||||
console.debug('From network', event.request.url)
|
||||
const resp = await fetch(event.request)
|
||||
|
||||
// This will trigger on an HTTP error such as 502.
|
||||
if (!resp.ok) {
|
||||
console.log('HTTP error', resp.status)
|
||||
console.error('HTTP error', resp.status)
|
||||
|
||||
// When JSON is expected, return that instead of the offline HTML page.
|
||||
return await offline(event, `${resp.status} ${resp.statusText}`)
|
||||
|
|
@ -73,7 +73,7 @@ async function fetchAsset(event) {
|
|||
}
|
||||
} catch (e) {
|
||||
// An error here is something like a DNS problem, not a regular HTTP problem.
|
||||
console.log('Network error', e, event.request.url)
|
||||
console.error('Network error', e, event.request.url)
|
||||
return await offline(event, e)
|
||||
}
|
||||
}
|
||||
|
|
@ -100,18 +100,22 @@ async function cleanupCache() {
|
|||
}
|
||||
|
||||
self.addEventListener('install', event => {
|
||||
console.log('SERVICE WORKER: install')
|
||||
console.debug('SERVICE WORKER: install')
|
||||
self.skipWaiting()
|
||||
event.waitUntil(precache())
|
||||
})
|
||||
|
||||
self.addEventListener('activate', event => {
|
||||
console.log('SERVICE WORKER: activate')
|
||||
console.debug('SERVICE WORKER: activate')
|
||||
self.clients.claim()
|
||||
event.waitUntil(cleanupCache())
|
||||
})
|
||||
|
||||
self.addEventListener('fetch', event => {
|
||||
//console.log('SERVICE WORKER: fetch', event.request.url)
|
||||
// console.debug('SERVICE WORKER: fetch', event.request.url)
|
||||
|
||||
if ({{ .DevMode }})
|
||||
return event
|
||||
|
||||
event.respondWith(fetchAsset(event))
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue