Files: d118d1c2ea174b51ca37f6c0c981c07850a83897 / sw.js
783 bytesRaw
1 | /* global self */ |
2 | |
3 | var VERSION = require('./package.json').version |
4 | var URLS = process.env.FILE_LIST |
5 | |
6 | // Respond with cached resources |
7 | self.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 |
15 | self.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 |
22 | self.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