feat: add static cache policy function
This commit is contained in:
@@ -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 ""
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user