From a877c17dc1ea541a54e46e3c3214e4d96b70e6cc Mon Sep 17 00:00:00 2001 From: Alex Shpak Date: Fri, 1 May 2020 17:45:23 +0200 Subject: Add precache to service worker --- assets/sw-register.js | 2 +- assets/sw.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/assets/sw-register.js b/assets/sw-register.js index 0b71f03..b67dbfd 100644 --- a/assets/sw-register.js +++ b/assets/sw-register.js @@ -1,4 +1,4 @@ -{{ $swJS := resources.Get "sw.js" | resources.ExecuteAsTemplate "sw.js" . }} +{{- $swJS := resources.Get "sw.js" | resources.ExecuteAsTemplate "sw.js" . -}} if (navigator.serviceWorker) { navigator.serviceWorker.register( "{{ $swJS.RelPermalink }}", diff --git a/assets/sw.js b/assets/sw.js index 0e7b0cf..2ff11fc 100644 --- a/assets/sw.js +++ b/assets/sw.js @@ -1,8 +1,10 @@ const cacheName = self.location.pathname const pages = [ +{{ if eq .Site.Params.BookServiceWorker "precache" }} {{ range .Site.AllPages -}} "{{ .RelPermalink }}", - {{ end }} + {{ end -}} +{{ end }} ]; self.addEventListener("install", function (event) { -- cgit v1.2.3