-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.js
59 lines (54 loc) · 1.91 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
/////////////////////////////////////////////////////////////////////////////
// You can find dozens of practical, detailed, and working examples of
// service worker usage on https://github.com/mozilla/serviceworker-cookbook
/////////////////////////////////////////////////////////////////////////////
// Cache name
var CACHE_NAME = 'cache-version-1';
// Files required to make this app work offline
var REQUIRED_FILES = [
'index.html',
'/',
'https://fonts.googleapis.com/css?family=Inter:400,500,700&display=swap',
'https://unpkg.com/[email protected]/dist/ionicons.js',
'assets/js/lib/jquery-3.4.1.min.js',
'assets/js/lib/popper.min.js',
'assets/js/lib/bootstrap.min.js',
'assets/js/plugins/owl-carousel/owl.carousel.min.js',
'assets/js/base.js',
'assets/css/inc/owl-carousel/owl.carousel.min.css',
'assets/css/inc/owl-carousel/owl.theme.default.css',
'assets/css/inc/bootstrap/bootstrap.min.css',
'assets/css/style.css'
];
self.addEventListener('install', function(event) {
// Perform install step: loading each required file into cache
event.waitUntil(
caches.open(CACHE_NAME)
.then(function(cache) {
// Add all offline dependencies to the cache
return cache.addAll(REQUIRED_FILES);
})
.then(function() {
return self.skipWaiting();
})
);
});
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request)
.then(function(response) {
// Cache hit - return the response from the cached version
if (response) {
return response;
}
// Not in cache - return the result from the live server
// `fetch` is essentially a "fallback"
return fetch(event.request);
}
)
);
});
self.addEventListener('activate', function(event) {
// Calling claim() to force a "controllerchange" event on navigator.serviceWorker
event.waitUntil(self.clients.claim());
});