Cache fonts and brand assets for a day

This commit is contained in:
Ian Gulliver
2026-08-16 13:52:55 -07:00
parent 2eaba6810c
commit b9bb8629a8
+7 -3
View File
@@ -58,9 +58,13 @@ func (staticFiles) Has(key string) bool {
return err == nil return err == nil
} }
func noCache(next http.Handler) http.Handler { func cacheControl(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-cache") if strings.HasPrefix(r.URL.Path, "/static/fonts/") || strings.HasPrefix(r.URL.Path, "/static/brand/") {
w.Header().Set("Cache-Control", "public, max-age=86400")
} else {
w.Header().Set("Cache-Control", "no-cache")
}
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
}) })
} }
@@ -133,5 +137,5 @@ func main() {
port = "8080" port = "8080"
} }
log.Printf("listening on http://localhost:%s", port) log.Printf("listening on http://localhost:%s", port)
log.Fatal(http.ListenAndServe(":"+port, noCache(handler))) log.Fatal(http.ListenAndServe(":"+port, cacheControl(handler)))
} }