-
Notifications
You must be signed in to change notification settings - Fork 26
/
service-worker.js
152 lines (145 loc) · 5 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
149
150
151
152
// https://developers.google.com/web/fundamentals/primers/service-workers/
// chrome: chrome://inspect/#service-workers
var CACHE_NAME = 'dwv-jqmobile-cache_v0.10.0-beta.0';
var urlsToCache = [
'./',
'./index.html',
// css
'./css/style.css',
// js
'./src/applauncher.js',
'./src/appgui.js',
'./src/dropbox.js',
'./src/google.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/double_tap.png',
'./resources/help/tap_and_hold.png',
'./resources/help/tap.png',
'./resources/help/touch_drag.png',
'./resources/help/twotouch_drag.png',
'./resources/help/twotouch_pinch.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-mobile/jquery.mobile-1.4.5.min.css',
'./ext/jquery-mobile/images/ajax-loader.gif',
'./ext/jquery-mobile/images/icons-svg/plus-white.svg',
'./ext/jquery-mobile/images/icons-svg/forward-white.svg',
'./ext/jquery-mobile/images/icons-svg/back-white.svg',
'./ext/jquery-mobile/images/icons-svg/info-white.svg',
'./ext/jquery-mobile/images/icons-svg/grid-black.svg',
'./ext/jquery-mobile/images/icons-png/plus-white.png',
'./ext/jquery-mobile/images/icons-png/forward-white.png',
'./ext/jquery-mobile/images/icons-png/back-white.png',
'./ext/jquery-mobile/images/icons-png/info-white.png',
'./ext/jquery-mobile/images/icons-png/grid-black.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-mobile/jquery.mobile-1.4.5.min.js',
'./ext/jquery-mobile/jquery.mobile-1.4.5.min.map',
'./node_modules/nprogress/nprogress.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',
'./ext/dropbox-dropins/dropins.js',
'./ext/google-api-javascript-client/client.js',
'./ext/google-api-javascript-client/api.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);
}
})
);
})
);
});