Generate pages list in sw.js
This commit is contained in:
parent
9c5fc12dd8
commit
c672d64f12
2 changed files with 14 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
{{ $swJS := resources.Get "sw.js" | resources.ExecuteAsTemplate "sw.js" . }}
|
||||
if (navigator.serviceWorker) {
|
||||
navigator.serviceWorker.register(
|
||||
"{{ "/sw.js" | relURL }}",
|
||||
"{{ $swJS.RelPermalink }}",
|
||||
{ scope: "{{ "/" | relURL }}" }
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,21 @@
|
|||
const cacheName = self.location.pathname
|
||||
const pages = [
|
||||
{{ range .Site.AllPages -}}
|
||||
"{{ .RelPermalink }}",
|
||||
{{ end }}
|
||||
];
|
||||
|
||||
self.addEventListener("install", function (event) {
|
||||
self.skipWaiting();
|
||||
|
||||
const precache = caches.open(cacheName).then((cache) => {
|
||||
return cache.addAll(pages);
|
||||
});
|
||||
event.waitUntil(precache);
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", (event) => {
|
||||
const cacheName = self.location.pathname
|
||||
const request = event.request;
|
||||
|
||||
if (request.method !== "GET") {
|
||||
return;
|
||||
}
|
Loading…
Reference in a new issue