generated from shgysk8zer0/jekyll-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsw-config.js
103 lines (95 loc) · 3.34 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
---
layout: null
---
/* eslint-env serviceworker */
/* eslint no-unused-vars: 0*/
'use strict';
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: "', '" }}',
'/webapp.webmanifest',
'https://apps.kernvalley.us/apps.json',
'https://cdn.kernvalley.us/img/markers.svg',
/* Other */
'/store/products.json',
].map(path => new URL(path, location.origin).href),
stale: [
/* Scripts */
'/js/index.min.js',
'{{ site.data.importmap.imports["@shgysk8zer0/polyfills"] }}',
'{{ site.data.importmap.imports["@shgysk8zer0/kazoo/"] }}harden.js',
'{{ site.data.importmap.imports["@shgysk8zer0/components/"] }}leaflet/map.min.js',
/* Custom Element Templates */
'{{ site.data.importmap.imports["@shgysk8zer0/components/"] }}/weather/current.html',
'{{ site.data.importmap.imports["@shgysk8zer0/components/"] }}/github/user.html',
/* CSS */
'/css/index.min.css',
'/css/store.css',
'{{ site.data.importmap.imports["@shgysk8zer0/components/"] }}weather/current.css',
'{{ site.data.importmap.imports["@shgysk8zer0/components/"] }}github/user.css',
'{{ site.data.importmap.imports["@shgysk8zer0/components/"] }}leaflet/map.css',
/* Images & Icons */
'/img/icons.svg',
'/img/apple-touch-icon.png',
'/img/icon-192.png',
'/img/favicon.svg',
'https://cdn.kernvalley.us/img/logos/firefox.svg',
'https://cdn.kernvalley.us/img/logos/chrome.svg',
'https://cdn.kernvalley.us/img/keep-kern-clean.svg',
'https://cdn.kernvalley.us/img/logos/play-badge.svg',
'/img/octicons/info.svg',
'/img/adwaita-icons/status/avatar-default.svg',
/* Event Images */
'/img/raster/rodeo.jpg',
'/img/raster/parade.jpg',
'/img/raster/encampment.jpg',
'/img/raster/coach-320.jpg',
/* Fonts */
'https://cdn.kernvalley.us/fonts/roboto.woff2',
'https://cdn.kernvalley.us/fonts/rye.woff2',
].map(path => new URL(path, location.origin).href),
allowed: [
'https://www.google-analytics.com/analytics.js',
'https://www.googletagmanager.com/gtag/js',
'https://i.imgur.com/',
'https://maps.wikimedia.org/osm-intl/',
'https://cdn.kernvalley.us/img/',
/https:\/\/\w+\.githubusercontent\.com\/u\/*/,
new URL('/img/raster/', location.origin).href,
/\.(jpg|png|webp|svg|gif)$/,
],
allowedFresh: [
new URL('/paths/', location.origin).href,
'https://api.openweathermap.org/data/',
'https://api.github.com/users/',
/\.(html|css|js|json)$/,
],
periodicSync: {
'main-assets': async () => await updateAssets([
'/js/index.min.js',
'/css/index.min.css',
'/img/icons.svg',
'/webapp.webmanifest',
]),
'pinned-pages': async () => await updateAssets([
'{{ site.pages | where: "pinned", true | map: "url" | join: "', '" }}'
]),
'recent-posts': async () => await updateAssets(['{{ site.posts | map: "url" | join: "', '" }}']),
}
};