-
Notifications
You must be signed in to change notification settings - Fork 19
/
service-worker.js
148 lines (141 loc) · 5.01 KB
/
service-worker.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// https://developers.google.com/web/fundamentals/primers/service-workers/
// chrome: chrome://inspect/#service-workers
var CACHE_NAME = 'dwv-jqui-cache_v0.10.0-beta.0';
var urlsToCache = [
'./',
'./index.html',
// css
'./css/style.css',
// js
'./src/applauncher.js',
'./src/appgui.js',
'./src/register-sw.js',
'./src/gui/custom.js',
'./src/gui/dropboxLoader.js',
'./src/gui/filter.js',
'./src/gui/generic.js',
'./src/gui/help.js',
'./src/gui/html.js',
'./src/gui/infoController.js',
'./src/gui/infoOverlay.js',
'./src/gui/loader.js',
'./src/gui/tools.js',
'./src/gui/undo.js',
'./src/utils/browser.js',
'./src/utils/modernizr.js',
// images
'./resources/icons/icon-16.png',
'./resources/icons/icon-32.png',
'./resources/icons/icon-64.png',
'./resources/icons/icon-128.png',
'./resources/icons/icon-256.png',
'./resources/help/click.png',
'./resources/help/double_click.png',
'./resources/help/mouse_drag.png',
'./resources/help/mouse_wheel.png',
// translations
'./resources/locales/de/translation.json',
'./resources/locales/en/translation.json',
'./resources/locales/es/translation.json',
'./resources/locales/fr/translation.json',
'./resources/locales/it/translation.json',
'./resources/locales/jp/translation.json',
'./resources/locales/ru/translation.json',
'./resources/locales/zh/translation.json',
// overlays
'./resources/locales/de/overlays.json',
'./resources/locales/en/overlays.json',
'./resources/locales/es/overlays.json',
'./resources/locales/fr/overlays.json',
'./resources/locales/it/overlays.json',
'./resources/locales/jp/overlays.json',
'./resources/locales/ru/overlays.json',
'./resources/locales/zh/overlays.json',
// third party
// css
'./ext/jquery-ui/themes/ui-darkness/jquery-ui-1.12.1.min.css',
'./ext/jquery-ui/themes/ui-darkness/images/ui-bg_glass_20_555555_1x400.png',
'./ext/jquery-ui/themes/ui-darkness/images/ui-bg_glass_40_0078a3_1x400.png',
'./ext/jquery-ui/themes/ui-darkness/images/ui-bg_glass_40_ffc73d_1x400.png',
'./ext/jquery-ui/themes/ui-darkness/images/' +
'ui-bg_gloss-wave_25_333333_500x100.png',
'./ext/jquery-ui/themes/ui-darkness/' +
'images/ui-bg_highlight-soft_80_eeeeee_1x100.png',
'./ext/jquery-ui/themes/ui-darkness/' +
'images/ui-bg_inset-soft_25_000000_1x100.png',
'./ext/jquery-ui/themes/ui-darkness/' +
'images/ui-bg_inset-soft_30_f58400_1x100.png',
'./ext/jquery-ui/themes/ui-darkness/images/ui-icons_222222_256x240.png',
'./ext/jquery-ui/themes/ui-darkness/images/ui-icons_4b8e0b_256x240.png',
'./ext/jquery-ui/themes/ui-darkness/images/ui-icons_a83300_256x240.png',
'./ext/jquery-ui/themes/ui-darkness/images/ui-icons_cccccc_256x240.png',
'./ext/jquery-ui/themes/ui-darkness/images/ui-icons_ffffff_256x240.png',
// js: dwv
'./node_modules/dwv/dist/dwv.min.js',
'./node_modules/jszip/dist/jszip.min.js',
'./node_modules/konva/konva.min.js',
'./node_modules/magic-wand-tool/dist/magic-wand.min.js',
// js: viewer
'./node_modules/jquery/dist/jquery.min.js',
'./ext/jquery-ui/jquery-ui-1.12.1.min.js',
'./ext/flot/jquery.flot.min.js',
'./node_modules/i18next/i18next.min.js',
'./node_modules/i18next-http-backend/i18nextHttpBackend.min.js',
'./node_modules/i18next-browser-languagedetector/' +
'i18nextBrowserLanguageDetector.min.js',
// js: decoders
'./node_modules/dwv/decoders/dwv/rle.js',
'./node_modules/dwv/decoders/dwv/decode-rle.js',
'./node_modules/dwv/decoders/pdfjs/jpx.js',
'./node_modules/dwv/decoders/pdfjs/arithmetic_decoder.js',
'./node_modules/dwv/decoders/pdfjs/decode-jpeg2000.js',
'./node_modules/dwv/decoders/pdfjs/util.js',
'./node_modules/dwv/decoders/pdfjs/jpg.js',
'./node_modules/dwv/decoders/pdfjs/decode-jpegbaseline.js',
'./node_modules/dwv/decoders/rii-mango/lossless-min.js',
'./node_modules/dwv/decoders/rii-mango/decode-jpegloss.js'
];
// install
self.addEventListener('install', function (event) {
event.waitUntil(
caches.open(CACHE_NAME).then(function (cache) {
return cache.addAll(urlsToCache);
})
);
});
// fetch
self.addEventListener('fetch', function (event) {
event.respondWith(
caches
.match(event.request, {ignoreSearch: true})
.then(function (response) {
// cache hit: return response
if (response) {
return response;
}
// fetch on network
return fetch(event.request);
})
);
});
// activate
self.addEventListener('activate', function (event) {
// delete caches which name starts with the same root as this one
var cacheRootName = CACHE_NAME;
var uPos = cacheRootName.lastIndexOf('_');
if (uPos !== -1) {
cacheRootName = cacheRootName.substr(0, uPos);
}
event.waitUntil(
caches.keys().then(function (cacheNames) {
return Promise.all(
cacheNames.map(function (cacheName) {
if (cacheName !== CACHE_NAME && cacheName.startsWith(cacheRootName)) {
console.log('Deleting cache: ' + cacheName);
return caches.delete(cacheName);
}
})
);
})
);
});