-
-
Notifications
You must be signed in to change notification settings - Fork 375
/
Copy pathindex.js
31 lines (26 loc) · 899 Bytes
/
index.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
import { registerRoute, setCatchHandler } from 'workbox-routing';
import { precacheAndRoute, getCacheKeyForURL } from 'workbox-precaching';
import { isNav } from './utils';
import { NETWORK_HANDLER, PRECACHING_OPTIONS } from './constants';
export function getFiles() {
return self.__WB_MANIFEST;
}
export function setupPrecaching(precacheFiles, precachingOptions) {
precacheAndRoute(precacheFiles, precachingOptions || PRECACHING_OPTIONS);
}
export function setupRouting() {
/**
* Adding this before `precacheAndRoute` lets us handle all
* the navigation requests even if they are in precache.
*/
registerRoute(({ event }) => isNav(event), NETWORK_HANDLER);
setCatchHandler(({ event }) => {
if (isNav(event)) {
return caches.match(
getCacheKeyForURL('/200.html') || getCacheKeyForURL('/index.html')
);
}
return Response.error();
});
}
export { PRECACHING_OPTIONS };