fix: add no-cache headers to prevent stale JS/CSS in browser
This commit is contained in:
parent
3e8583b367
commit
b053807f0c
1 changed files with 15 additions and 1 deletions
16
main.go
16
main.go
|
|
@ -60,11 +60,25 @@ func main() {
|
||||||
|
|
||||||
uiRouter.AttachHandlerToMux(mux)
|
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)
|
addr := fmt.Sprintf("127.0.0.1:%d", config.Port)
|
||||||
log.Printf("zoraxy-headers v%d.%d.%d listening on %s (zoraxy API %s)",
|
log.Printf("zoraxy-headers v%d.%d.%d listening on %s (zoraxy API %s)",
|
||||||
spec.VersionMajor, spec.VersionMinor, spec.VersionPatch, addr, baseURL)
|
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)
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue