-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
66 lines (61 loc) · 1.87 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
'use strict';
var cacheno = 3;
var cacheno_old = 2;
var cachename = 'journal-club-v' + cacheno;
var cachename_old = 'journal-club-v' + cacheno_old;
var cachefiles = [
'./',
'./index.php',
'./manifest.json',
'./js/gallery.min.js',
'./js/main.min.js',
'./js/menue.min.js',
'./images/campusnet_banner.png',
'./images/01_carousel.jpg',
'./images/02_carousel.jpg',
'./images/03_carousel.jpg',
'./images/04_carousel.jpg',
'./images/arxiv.jpg',
'./images/dottorato.jpg',
'./images/infn.jpg',
'./images/inspire.jpg',
'./images/pictures_button_left.png',
'./images/pictures_button_right.png',
'./images/bg/bg01.png',
'./images/bg/bg02.png',
'./images/bg/bg03.png',
'./css/main.min.css',
'./bulletin/message.md',
'./bulletin/Parsedown.php'
];
self.addEventListener('install', function(e) {
console.log('[SW] Installing Service Worker.');
e.waitUntil(
caches.open(cachename).then(function(cache) {
console.log('[SW] Caching ' + cachename + '.');
return cache.addAll(cachefiles);
})
);
self.skipWaiting();
});
self.addEventListener('activate', function(e) {
console.log('[SW] Activating new Service Worker.');
console.log('[SW] Deleting old cache: ' + cachename_old + '.');
e.waitUntil(
caches.delete(cachename_old)
);
});
self.addEventListener('fetch', function(e) {
e.respondWith(
caches.open(cachename).then(function(cache) {
console.log('[SW] Fetching ' + e.request.url + '.');
return cache.match(e.request).then(function(response) {
var fetchpromise = fetch(e.request).then(function(network) {
cache.put(e.request, network.clone());
return network;
})
return response || fetchpromise;
});
})
);
});