fix: add no-cache headers to prevent stale JS/CSS in browser

This commit is contained in:
Claus Lohmar 2026-10-14 15:04:59 +00:00
parent 3e8583b367
commit b053807f0c

16
main.go
View file

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