feat: add static cache policy function

This commit is contained in:
2026-07-03 02:55:10 +02:00
parent 01776f4eef
commit 32fed1eee2

View File

@@ -47,7 +47,6 @@ func isCompressedPath(path string) bool {
}
}
//nolint:unused
func isImagePath(path string) bool {
switch strings.ToLower(filepath.Ext(path)) {
case ".avif", ".gif", ".ico", ".jpeg", ".jpg", ".png", ".svg", ".webp":
@@ -56,3 +55,19 @@ func isImagePath(path string) bool {
return false
}
}
//nolint:unused
func staticCachePolicy(r *http.Request) string {
path := r.URL.Path
switch {
case strings.HasPrefix(path, "/dist/"):
if r.URL.Query().Get("v") != "" {
return "public, max-age=31536000, immutable"
}
return "public, max-age=0, must-revalidate"
case strings.HasPrefix(path, "/static/assets/") && isImagePath(path):
return "public, max-age=86400"
default:
return ""
}
}