From 509cf026fda761c792bbedfc26e5592f4220f24f Mon Sep 17 00:00:00 2001 From: Tine Date: Sun, 28 Apr 2024 16:23:41 +0200 Subject: [PATCH] feat: add cache headers for static and index --- internal/handlers/index.go | 2 ++ pkg/server/routes.go | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/internal/handlers/index.go b/internal/handlers/index.go index 12180e2..de1892b 100644 --- a/internal/handlers/index.go +++ b/internal/handlers/index.go @@ -165,6 +165,8 @@ func (h *BaseHandler) Index(c echo.Context) error { } } + c.Response().Header().Set("Cache-Control", "max-age=10") + return c.Render(http.StatusOK, "index.tmpl", &IndexData{ Base: &components.Base{ NavbarActive: GetPageByTitle(Pages, "Status"), diff --git a/pkg/server/routes.go b/pkg/server/routes.go index a5fe8cb..4cb3ce0 100644 --- a/pkg/server/routes.go +++ b/pkg/server/routes.go @@ -35,6 +35,12 @@ func Routes( // Server static files stat := e.Group("/static") + stat.Use(func(next echo.HandlerFunc) echo.HandlerFunc { + return func(c echo.Context) error { + c.Response().Header().Set("Cache-Control", "public, max-age=60") + return next(c) + } + }) stat.Use(middleware.StaticWithConfig(middleware.StaticConfig{ Filesystem: http.FS(static.Static), }))