summaryrefslogtreecommitdiff
path: root/worker.js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2018-06-29 18:58:53 +0300
committerAndrew Dolgov <[email protected]>2018-06-29 18:58:53 +0300
commit8a23fe6dbe7a5a98ef0d3c83faed584817894a69 (patch)
tree3499dd4d7fa3dbfaee29d08211828b65a136b921 /worker.js
parent7481076e80ac56a5d7e371a206b6a84d81baa43c (diff)
worker: cleanup previous cache versions
Diffstat (limited to 'worker.js')
-rw-r--r--worker.js15
1 files changed, 14 insertions, 1 deletions
diff --git a/worker.js b/worker.js
index 7b1d424..983dc25 100644
--- a/worker.js
+++ b/worker.js
@@ -1,6 +1,7 @@
//importScripts('lib/localforage.min.js');
-const CACHE_NAME = 'epube-v2';
+const CACHE_PREFIX = 'epube';
+const CACHE_NAME = CACHE_PREFIX + '-v2';
const CACHE_URLS = [
'read.html',
'js/common.js',
@@ -41,6 +42,18 @@ self.addEventListener('install', function(event) {
);
});
+self.addEventListener('activate', function(event) {
+ event.waitUntil(
+ caches.keys().then(function(keyList) {
+ return Promise.all(keyList.map(function(key) {
+ if (key.indexOf(CACHE_PREFIX) != -1 && key != CACHE_NAME) {
+ return caches.delete(key);
+ }
+ }));
+ })
+ );
+});
+
function send_message(client, msg) {
client.postMessage(msg);
}