Initial commit with user management
This commit is contained in:
commit
a1a928e7cb
98 changed files with 13042 additions and 0 deletions
45
static/service_worker.js
Normal file
45
static/service_worker.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
const CACHE_NAME = 'notes2-{{ .VERSION }}'
|
||||
const CACHED_ASSETS = [
|
||||
'/',
|
||||
'/js/{{ .VERSION }}/app.mjs',
|
||||
]
|
||||
|
||||
async function precache() {
|
||||
const cache = await caches.open(CACHE_NAME)
|
||||
return cache.addAll(CACHED_ASSETS)
|
||||
}
|
||||
|
||||
async function fetchAsset(event) {
|
||||
try {
|
||||
return await fetch(event.request)
|
||||
} catch (e) {
|
||||
const cache = await caches.open(CACHE_NAME)
|
||||
return cache.match(event.request)
|
||||
}
|
||||
}
|
||||
|
||||
async function cleanupCache() {
|
||||
const keys = await caches.keys()
|
||||
const keysToDelete = keys.map(key => {
|
||||
if (key !== CACHE_NAME)
|
||||
return caches.delete(key)
|
||||
})
|
||||
return Promise.all(keysToDelete)
|
||||
}
|
||||
|
||||
self.addEventListener('install', event => {
|
||||
console.log('SERVICE WORKER: install')
|
||||
self.skipWaiting()
|
||||
event.waitUntil(precache())
|
||||
})
|
||||
|
||||
self.addEventListener('activate', event => {
|
||||
console.log('SERVICE WORKER: activate')
|
||||
self.clients.claim()
|
||||
event.waitUntil(cleanupCache())
|
||||
})
|
||||
|
||||
self.addEventListener('fetch', event => {
|
||||
//console.log('SERVICE WORKER: fetch')
|
||||
event.respondWith(fetchAsset(event))
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue