mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-05 08:02:53 +00:00
fix(webui): stop browsers serving a stale embedded UI after upgrade (#112)
The management UI is embedded in the binary (//go:embed) and served through http.FileServerFS. Those responses carry no Cache-Control, and the embed FS reports a zero modification time, so there is no Last-Modified or ETag either. Browsers are therefore free to apply heuristic caching and keep an old index.html/app.js/styles.css for hours. That is invisible until the operator upgrades the binary: the new backend then serves requests that the cached old frontend does not know about, so newly added pages never appear (or the UI breaks) until the cache expires or the user hard-refreshes. Set Cache-Control: no-cache on the embedded assets so the browser always revalidates. Revalidation is cheap against a local server, and it makes the UI version follow the binary version, which is the invariant the embed implies. Co-authored-by: WengeLiu101 <233876084+WengeLiu101@users.noreply.github.com>
This commit is contained in:
1 parent
4e2edbf1e6
commit
05874a5bf0
1 file changed
+7
@@ -97,6 +97,13 @@ func (a *Server) staticHandler() http.Handler {
|
||||
r.URL.Path = "/"
|
||||
}
|
||||
}
|
||||
// The UI ships inside the binary and only changes when the binary does,
|
||||
// so a browser that cached app.js/styles.css under a heuristic freshness
|
||||
// lifetime keeps running the previous build's frontend against the new
|
||||
// backend — the UI then shows stale pages (or breaks outright) until the
|
||||
// cache happens to expire or the operator hard-refreshes. Force
|
||||
// revalidation instead.
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
files.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user