-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsw.js
More file actions
47 lines (43 loc) · 1.16 KB
/
sw.js
File metadata and controls
47 lines (43 loc) · 1.16 KB
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
importScripts(
'https://storage.googleapis.com/workbox-cdn/releases/6.2.0/workbox-sw.js'
)
// workbox.setConfig({ debug: true })
const {
routing: { registerRoute, setCatchHandler },
strategies: { CacheFirst, NetworkFirst, StaleWhileRevalidate },
cacheableResponse: { CacheableResponse, CacheableResponsePlugin },
expiration: { ExpirationPlugin, CacheExpiration },
precaching: { matchPrecache, precacheAndRoute },
} = workbox
// Cache html, script.js, data.db etc using stale-while-revalidate
registerRoute(
({ request, url }) =>
request.mode === 'navigate' ||
url.pathname === '/josaa-cutoffs/script.js' ||
url.pathname === '/josaa-cutoffs/styles.css' ||
url.pathname === '/josaa-cutoffs/data.db.gz',
new StaleWhileRevalidate({
cacheName: 'stale-while-revalidate',
plugins: [
new CacheableResponsePlugin({
statuses: [200],
}),
],
})
)
// Cache cdns and the rest using cache-first
registerRoute(
() => true,
new CacheFirst({
cacheName: 'static-assets',
plugins: [
new CacheableResponsePlugin({
statuses: [0, 200],
}),
new ExpirationPlugin({
maxEntries: 32,
maxAgeSeconds: 24 * 60 * 60 * 30, // 1 month
}),
],
})
)