-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsw.js
85 lines (82 loc) · 2.45 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
if ("serviceWorker" in navigator) {
navigator.serviceWorker
.register("/sw.js")
.then(serviceWorker => {
console.log("Service Worker registered: ", serviceWorker);
})
.catch(error => {
console.error("Error registering the Service Worker: ", error);
});
}
const CACHE_NAME = 't2s-cache';
const urlsToCache = [
'sw.js',
'manifest.json',
'ani_equalizer_white.gif',
'icon-192.png',
'icon-512.png',
'favicon.ico',
'favicon.png',
'/assets/css/lity.min.css',
'/assets/css/quill.snow.css',
'/assets/css/richVoiceEditor.css',
'/assets/css/material-palenight.css',
'/assets/css/one-light.css',
'/assets/css/style.css',
'/assets/js/highlight.min.js',
'/assets/js/lity.min.js',
'/assets/js/quill.js',
'/assets/js/richVoiceEditor_options.js',
'/assets/js/richVoiceEditor.js',
'/assets/js/toastr_options.js',
'/assets/js/cookies.js',
'/assets/js/helpers.js',
'/assets/js/main.js',
'/assets/icons/emphasis.svg',
'/assets/icons/pitch-high.svg',
'/assets/icons/pitch-low.svg',
'/assets/icons/pitch-x-high.svg',
'/assets/icons/pitch-x-low.svg',
'/assets/icons/rate-fast.svg',
'/assets/icons/rate-slow.svg',
'/assets/icons/rate-x-fast.svg',
'/assets/icons/rate-x-slow.svg',
'/assets/icons/spellout.svg',
'https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css',
'https://fonts.googleapis.com/css?family=Nunito&display=swap',
'https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css',
'https://unpkg.com/swiper/swiper-bundle.min.css',
'https://code.jquery.com/jquery-3.4.1.min.js',
'https://kit.fontawesome.com/fbb35493dc.js',
'https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js',
'https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js',
'https://unpkg.com/swiper/swiper-bundle.min.js',
];
console.log('loading sw');
self.addEventListener('install', function(event) {
// Perform install steps
console.log('installing sw');
event.waitUntil(
caches.open(CACHE_NAME)
.then(function(cache) {
console.log('Opened cache');
let x = cache.addAll(urlsToCache);
console.log('cache added');
return x;
})
);
});
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);
}
)
);
});