forked from plus62store/new
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsw.js
51 lines (43 loc) · 1.19 KB
/
sw.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
---
layout: none
---
importScripts('https://cdn.jsdelivr.net/npm/workbox-cdn/workbox/workbox-sw.js');
const { registerRoute } = workbox.routing;
const { CacheFirst, NetworkFirst, StaleWhileRevalidate } = workbox.strategies;
const { CacheableResponse } = workbox.cacheableResponse;
workbox.core.setCacheNameDetails({
prefix: '{{site.url}}',
suffix: '{{ site.time | date: "%Y-%m" }}'
});
registerRoute(
'/',
new NetworkFirst()
);
registerRoute(
/page[0-99]/,
new NetworkFirst()
)
registerRoute(
new RegExp('/\\d{4}/\\d{2}/\\d{2}/.+'),
new StaleWhileRevalidate()
)
workbox.precaching.precacheAndRoute([
{% for post in site.posts limit:14 -%}
{ url: '{{ post.url }}', revision: '{{ post.date | date: "%Y-%m-%d"}}' },
{% endfor -%}
{ url: '/', revision: '{{ site.time | date: "%Y%m%d%H%M" }}' },
{ url: '/nonton/', revision: '{{ site.time | date: "%Y%m%d%H%M" }}' },
{ url: '/assets/css/style.css', revision: '{{ site.time | date: "%Y%m%d%H%M" }}' }
])
registerRoute(
({request}) => request.destination === 'image' ,
new CacheFirst({
plugins: [
new CacheableResponse({statuses: [0, 200]})
],
})
);
registerRoute(
/\/(images|favicon|css)/,
new CacheFirst()
);