This commit is contained in:
2026-04-28 16:00:39 -06:00
parent 1e998dabf3
commit 7df663d9c4
12 changed files with 493 additions and 128 deletions
+9 -1
View File
@@ -6,6 +6,8 @@ import (
"io"
"log"
"net/http"
"path/filepath"
"regexp"
"strings"
"github.com/joho/godotenv"
@@ -19,6 +21,8 @@ type gzipResponseWriter struct {
http.ResponseWriter
}
var fingerprintPattern = regexp.MustCompile(`[-.][a-f0-9]{8,}\.`)
func (w gzipResponseWriter) Write(b []byte) (int, error) {
return w.Writer.Write(b)
}
@@ -43,7 +47,11 @@ func gzipMiddleware(next http.Handler) http.Handler {
func cacheMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "public, max-age=31536000")
if fingerprintPattern.MatchString(filepath.Base(r.URL.Path)) {
w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
} else {
w.Header().Set("Cache-Control", "public, max-age=3600")
}
next.ServeHTTP(w, r)
})
}