-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
52 lines (43 loc) · 1.46 KB
/
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
import { NetworkFirst /* , CacheFirst */ } from "workbox-strategies"
import { CacheableResponsePlugin } from "workbox-cacheable-response"
// import { ExpirationPlugin } from "workbox-expiration"
import { registerRoute, NavigationRoute /* , Route */ } from "workbox-routing"
import { cleanupOutdatedCaches, precacheAndRoute } from "workbox-precaching"
import { offlineFallback } from "workbox-recipes"
cleanupOutdatedCaches()
let WB_MANIFEST = self.__WB_MANIFEST
if (Array.isArray(WB_MANIFEST)) {
WB_MANIFEST = WB_MANIFEST.filter((wbm) => {
const { url } = wbm
if (url && typeof url === "string") return url.match(/_next\/static/)
})
WB_MANIFEST.push({ url: "/site.webmanifest", revision: Date.now() })
}
precacheAndRoute(WB_MANIFEST || [])
const cacheableOk = new CacheableResponsePlugin({
statuses: [0, 200],
})
// const expiration = new ExpirationPlugin({
// maxEntries: 50,
// maxAgeSeconds: 60 * 60 * 24 * 7 /* 1 week */,
// purgeOnQuotaError: true,
// })
const navigationRoute = new NavigationRoute(
new NetworkFirst({
cacheName: "navigations",
plugins: [cacheableOk],
})
)
// const assetRoute = new Route(
// ({ request }) => {
// const { destination: dst } = request
// return dst.match("image|style|script|font")
// },
// new CacheFirst({
// cacheName: "assets",
// plugins: [expiration, cacheableOk],
// })
// )
registerRoute(navigationRoute)
// registerRoute(assetRoute)
offlineFallback({ pageFallback: "/offline" })