diff --git a/internal/api/server.go b/internal/api/server.go index 170551479..eb40a72a6 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -319,6 +319,7 @@ func newDashboardRequestHandler() (http.HandlerFunc, error) { } // Path is a file + httputil.SetCacheHeaders(w, 30*24*time.Hour, 7*24*time.Hour) handler.ServeHTTP(w, req) }) diff --git a/internal/http/http.go b/internal/http/http.go index e969052e2..03f097645 100644 --- a/internal/http/http.go +++ b/internal/http/http.go @@ -20,3 +20,11 @@ func SetNoCacheHeaders(w http.ResponseWriter) { w.Header().Set(k, v) } } + +func SetCacheHeaders(w http.ResponseWriter, maxAge time.Duration, timeUntilExpiry time.Duration) { + if w == nil { + return + } + w.Header().Set("Cache-Control", "public, max-age="+maxAge.String()) + w.Header().Set("Expires", time.Now().Add(timeUntilExpiry).Format(time.RFC1123)) +}