summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-23 21:35:52 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-23 21:35:52 +0200
commitbfa8df7b36ccbd44703e0705d51a2ed553a23164 (patch)
tree5b760ff95f6e9498dec77f813eddd5538c0b1177
parentba3c501ec516e1cc58870708a83874b10fc4584a (diff)
downloadlectio-bfa8df7b36ccbd44703e0705d51a2ed553a23164.tar.gz
lectio-bfa8df7b36ccbd44703e0705d51a2ed553a23164.zip
web: no-store responses + robust theme-link swap (fixes stale-cache 'theme switch stopped working')
-rw-r--r--internal/web/server.go12
-rw-r--r--internal/web/templates/index.html2
2 files changed, 12 insertions, 2 deletions
diff --git a/internal/web/server.go b/internal/web/server.go
index 50bf45d..10401ed 100644
--- a/internal/web/server.go
+++ b/internal/web/server.go
@@ -46,7 +46,17 @@ func NewServer(cfg config.Config) http.Handler {
}
mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServer(http.FS(staticSub))))
- return mux
+ return noStore(mux)
+}
+
+// noStore stops the browser caching any lectio-web response, so a rebuilt or
+// reinstalled server never has an old page, base.css or theme.css served from
+// cache (which presents as "switching themes stopped working" after an update).
+func noStore(h http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Cache-Control", "no-store")
+ h.ServeHTTP(w, r)
+ })
}
// today is lectio-web's "no ?date=" default, in the YYYY-MM-DD form every
diff --git a/internal/web/templates/index.html b/internal/web/templates/index.html
index cc56a09..a1247e6 100644
--- a/internal/web/templates/index.html
+++ b/internal/web/templates/index.html
@@ -61,7 +61,7 @@
<label class="theme-picker">motyw
<select id="theme-select"
- onchange="document.getElementById('theme').href='/theme.css?name='+encodeURIComponent(this.value)">
+ onchange="var o=document.getElementById('theme'),n=o.cloneNode(false);n.setAttribute('href','/theme.css?name='+encodeURIComponent(this.value));o.replaceWith(n);">
{{range .ThemeOpts}}
<option value="{{.Name}}" {{if .Selected}}selected{{end}}>{{.Name}}</option>
{{end}}