Opt: web dist home page use cache

pull/21/head
zijiren233 1 year ago
parent 7e1c6ab5d8
commit f9844dd58e

@ -17,14 +17,7 @@ func Init(e *gin.Engine) {
web := e.Group("/web")
web.Use(func(ctx *gin.Context) {
if ctx.Request.URL.Path == "/web/" {
ctx.Header("Cache-Control", "no-store")
} else {
ctx.Header("Cache-Control", "public, max-age=31536000")
}
ctx.Next()
})
web.Use(middlewares.NewDistCacheControl("/web/"))
web.StaticFS("", http.FS(public.Public))
}

@ -0,0 +1,14 @@
package middlewares
import "github.com/gin-gonic/gin"
func NewDistCacheControl(prefix string) gin.HandlerFunc {
return func(ctx *gin.Context) {
if ctx.Request.URL.Path == prefix {
ctx.Header("Cache-Control", "no-cache, max-age=300")
} else {
ctx.Header("Cache-Control", "public, max-age=31536000")
}
ctx.Next()
}
}
Loading…
Cancel
Save