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) + }) +}