-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsw-config.js
79 lines (72 loc) · 2.3 KB
/
sw-config.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
layout: null
---
'use strict';
/* eslint-env serviceworker */
/* eslint no-unused-vars: 0 */
async function updateAssets(assets, {
referrerPolicy = 'no-referrer',
version = '{{ site.data.app.version | default: site.version }}',
} = {}) {
if (Array.isArray(assets) && assets.length !== 0) {
const cache = await caches.open(version);
await Promise.allSettled(assets.filter(url => url.length !== 0).map(async url => {
const req = new Request(new URL(url, location.origin), { referrerPolicy: 'no-referrer' });
const resp = await fetch(req);
if (resp.ok) {
await cache.put(req, resp);
}
}));
}
}
const config = {
version: '{{ site.data.app.version | default: site.version }}',
fresh: [
'{{ site.pages | where: "pinned", true | map: "url" | join: "', '" }}',
'https://apps.kernvalley.us/apps.json',
'/webapp.webmanifest',
].map(path => new URL(path, location.origin).href),
stale: [
/* JS, `customElements`, etc. */
'{{ site.data.importmap.imports["@shgysk8zer0/polyfills/"] }}all.min.js',
'/js/index.min.js',
'/js/create.min.js',
/* CSS */
'/css/index.min.css',
/* Images & Icons */
'/img/icons.svg',
'/img/apple-touch-icon.png',
'/img/icon-192.png',
'/img/favicon.svg',
'https://cdn.kernvalley.us/img/adwaita-icons/actions/mail-send.svg',
'https://cdn.kernvalley.us/img/adwaita-icons/actions/mark-location.svg',
'https://cdn.kernvalley.us/img/octicons/file-media.svg',
'https://cdn.kernvalley.us/img/logos/play-badge.svg',
'https://cdn.kernvalley.us/img/logos/instagram.svg',
/* Fonts */
'https://cdn.kernvalley.us/fonts/roboto.woff2',
].map(path => new URL(path, location.origin).href),
allowed: [
'https://i.imgur.com/',
'https://cdn.kernvalley.us/img/branding/',
/https:\/\/[a-z-]+\.disqus\.com\/embed\.js/,
/https:\/\/\w+\.githubusercontent\.com\/u\/*/,
/\.(jpg|png|gif|webp|ico|woff2|woff|ttf|oft)$/,
],
allowedFresh: [
'https://api.github.com/users/',
'https://api.openweathermap.org/data/2.5/weather',
/\.(js|css|html|json)$/,
],
periodicSync: {
'main-assets': async () => await updateAssets([
'/js/index.min.js',
'/css/index.min.css',
'/img/icons.svg',
'/webapp.webmanifest',
]),
'upcoming-events': async () => await updateAssets([
'/', //'{{ site.events | where: "pinned", true | map: "url" | join: "', '" }}',
]),
},
};