-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
37 lines (36 loc) · 1.31 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
// Here comes the install event!
// This only happens once, when the browser sees this
// version of the ServiceWorker for the first time.
self.addEventListener('install', function (event) {
// We pass a promise to event.waitUntil to signal how
// long install takes, and if it failed
event.waitUntil(
// We open a cache…
caches.open('simple-sw-v1').then(function (cache) {
// And add resources to it
return cache.addAll([
'./',
'index.html',
'devfest_logo.png'
]);
})
);
});
// The fetch event happens for the page request with the
// ServiceWorker's scope, and any request made within that
// page
self.addEventListener('fetch', function (event) {
// Calling event.respondWith means we're in charge
// of providing the response. We pass in a promise
// that resolves with a response object
event.respondWith(
// First we look for something in the caches that
// matches the request
caches.match(event.request).then(function (response) {
// If we get something, we return it, otherwise
// it's null, and we'll pass the request to
// fetch, which will use the network.
return response || fetch(event.request);
})
);
});