git ssb

0+

Zach! / music-visions



Tree: d118d1c2ea174b51ca37f6c0c981c07850a83897

Files: d118d1c2ea174b51ca37f6c0c981c07850a83897 / sw.js

783 bytesRaw
1/* global self */
2
3var VERSION = require('./package.json').version
4var URLS = process.env.FILE_LIST
5
6// Respond with cached resources
7self.addEventListener('fetch', function (e) {
8 e.respondWith(self.caches.match(e.request).then(function (request) {
9 if (request) return request
10 else return self.fetch(e.request)
11 }))
12})
13
14// Register worker
15self.addEventListener('install', function (e) {
16 e.waitUntil(self.caches.open(VERSION).then(function (cache) {
17 return cache.addAll(URLS)
18 }))
19})
20
21// Remove outdated resources
22self.addEventListener('activate', function (e) {
23 e.waitUntil(self.caches.keys().then(function (keyList) {
24 return Promise.all(keyList.map(function (key, i) {
25 if (keyList[i] !== VERSION) return self.caches.delete(keyList[i])
26 }))
27 }))
28})
29

Built with git-ssb-web