Skip to content

Commit 12ac501

Browse files
committed
fix: disable browser caching for static files in dev mode
Wrap the dev mode file server with Cache-Control: no-store so the browser always fetches JS files fresh from disk on every refresh, without needing a hard refresh (Ctrl+Shift+R).
1 parent ae757d7 commit 12ac501

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

internal/staticserve/static_serve.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ func RenderPreactHTML(data *result.HTMLTemplateData) (string, error) {
5151
func GetStaticHandler() http.Handler {
5252
if dir := devStaticDir(); dir != "" {
5353
_ = mime.AddExtensionType(".mjs", "application/javascript; charset=utf-8")
54-
return http.FileServer(http.Dir(dir))
54+
fs := http.FileServer(http.Dir(dir))
55+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
56+
w.Header().Set("Cache-Control", "no-store")
57+
fs.ServeHTTP(w, r)
58+
})
5559
}
5660
return result.GetStaticHandler(staticFiles)
5761
}

0 commit comments

Comments
 (0)