]>
git.r.bdr.sh - rbdr/r.bdr.sh/blob - jekyll/service_worker.js
c439ea801079f1d05fafc8426c689b67685da8c3
10 // Response for when network is not available
12 errorResponse: '<h1>Service Unavailable</h1>',
14 // Main entry point, adds event listeners for service worker
18 self
.addEventListener('install', internals
.onInstall
);
19 self
.addEventListener('fetch', internals
.onFetch
);
20 self
.addEventListener('activate', internals
.onActivate
);
23 // Runs on installation of the service worker
28 caches
.open(`${internals.version}/essentials`)
31 return cache
.addAll(internals
.offlineEssentials
)
36 // Runs when a path is fetched, returns files from cache
40 if (event
.request
.method
!== 'GET') {
45 caches
.match(event
.request
)
48 const freshContent
= fetch(event
.request
)
51 caches
.open(`${internals.version}/paths`)
52 .then((cache
) => cache
.put(event
.request
, response
.clone()));
53 }, internals
.onFetchFail
)
54 .catch(internals
.onFetchFail
);
56 return cached
|| freshContent
;
67 return Promise
.all(keys
68 .filter((key
) => !key
.startsWith(internals
.version
))
69 .map((key
) => caches
.delete(key
))
75 // Responds with Servie Unavailable if we can't fetch a
80 return new Response(internals
.errorResponse
, {
82 statusText: 'Service Unavailable',
83 headers: new Headers({
84 'Content-Type': 'text/html'