From b053807f0c183a1f579b1999d2044db6102edcf2 Mon Sep 17 00:00:00 2001 From: cclohmar Date: Wed, 14 Oct 2026 15:04:59 +0000 Subject: [PATCH] fix: add no-cache headers to prevent stale JS/CSS in browser --- main.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 2a153ac..f82df0c 100644 --- a/main.go +++ b/main.go @@ -60,11 +60,25 @@ func main() { uiRouter.AttachHandlerToMux(mux) + // Wrap with no-cache middleware so the browser always fetches fresh assets + // (the plugin binary embeds the web files, so URLs never change and the + // browser would otherwise cache stale JS/CSS indefinitely). + wrappedMux := noCacheMiddleware(mux) + addr := fmt.Sprintf("127.0.0.1:%d", config.Port) log.Printf("zoraxy-headers v%d.%d.%d listening on %s (zoraxy API %s)", spec.VersionMajor, spec.VersionMinor, spec.VersionPatch, addr, baseURL) - if err := http.ListenAndServe(addr, mux); err != nil { + if err := http.ListenAndServe(addr, wrappedMux); err != nil { log.Fatalf("server error: %v", err) } } + +// noCacheMiddleware disables caching for all plugin responses. +func noCacheMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Cache-Control", "no-store, no-cache, must-revalidate") + w.Header().Set("Pragma", "no-cache") + next.ServeHTTP(w, r) + }) +}