diff --git a/http/http.go b/http/http.go index 608c807..1f414e3 100644 --- a/http/http.go +++ b/http/http.go @@ -3,6 +3,7 @@ package http import ( "io/fs" "net/http" + "strings" "git.javil.eu/jacob1123/budgeteer" "git.javil.eu/jacob1123/budgeteer/bcrypt" @@ -39,6 +40,7 @@ func (h *Handler) Serve() { if err != nil { panic("couldn't open static files") } + router.Use(headersByRequestURI()) router.StaticFS("/static", http.FS(static)) router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "index.html", nil) }) @@ -83,3 +85,11 @@ func (h *Handler) Serve() { router.Run(":1323") } + +func headersByRequestURI() gin.HandlerFunc { + return func(c *gin.Context) { + if strings.HasPrefix(c.Request.RequestURI, "/static/") { + c.Header("Cache-Control", "max-age=86400") + } + } +}