-
Notifications
You must be signed in to change notification settings - Fork 6
/
sw.js
70 lines (67 loc) · 2.07 KB
/
sw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// version 1
// v0
var prefix_name = "croppy_"
var CACHE_NAME = prefix_name + 'cache_1_56';
var cacheWhitelist = [CACHE_NAME];
var urlsToCache = [
'./',
'./index.html',
'./promo-bottom.png',
'./promo-img.png',
'./images/croppy.png',
'./images/Croppy_anniver.small.png',
'./images/Croppy_ver3.small.png',
'./images/Croppy_xmas_1.jpg',
'./images/croppy_split.jpg',
'./manifest.json',
'https://knicknic.github.io/wasm-imagemagick/magick.js',
'https://knicknic.github.io/wasm-imagemagick/magick.wasm',
'https://knicknic.github.io/wasm-imagemagick/magickApi.js',
'./instructions.html',
'./favicon.png',
'./add_webtoon_croppy.js',
'./webtoon_bookmarklet.html',
'./webtoon_croppy.html',
'https://cdn.jsdelivr.net/g/filesaver.js',
'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.5/jszip.min.js',
//"https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif"
];
self.addEventListener('activate', function(event) {
event.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.map(function(cacheName) {
if (cacheName.startsWith(prefix_name) && cacheWhitelist.indexOf(cacheName) ===-1) {
//alert("asdf")
//self.postMessage("deleting cache " + cacheName)
return caches.delete(cacheName);
}
})
);
})
);
});
self.addEventListener('install', function(event) {
self.skipWaiting();
// Perform install steps
event.waitUntil(
caches.open(CACHE_NAME)
.then(function(cache) {
console.log('Opened cache: ' + CACHE_NAME);
return cache.addAll(urlsToCache);
})
);
});
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request)
.then(function(response) {
// Cache hit - return response
if (response) {
return response;
}
return fetch(event.request);
}
)
);
});