From e58ca686e3176e5b45b9db9e93319a1e5a58a520 Mon Sep 17 00:00:00 2001 From: BoYanZh Date: Thu, 15 Dec 2022 17:48:29 +0800 Subject: [PATCH] feat: cache static files (#2715) --- server/static/static.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/static/static.go b/server/static/static.go index 74c4a7f7..adfac1ba 100644 --- a/server/static/static.go +++ b/server/static/static.go @@ -65,6 +65,13 @@ func UpdateIndex() { func Static(r *gin.Engine) { InitIndex() folders := []string{"assets", "images", "streamer"} + r.Use(func(c *gin.Context) { + for i := range folders { + if strings.HasPrefix(c.Request.RequestURI, fmt.Sprintf("/%s/", folders[i])) { + c.Header("Cache-Control", "max-age=86400") + } + } + }) for i, folder := range folders { folder = "dist/" + folder sub, err := fs.Sub(public.Public, folder)