From a19d3d69327f0be982f2605025f459a506d60d52 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Tue, 7 Dec 2021 21:32:20 +0000 Subject: [PATCH] Try to enable caching --- http/http.go | 10 ++++++++++ 1 file changed, 10 insertions(+) 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") + } + } +}