Skip to content

Commit

Permalink
Add cache-control header to static assets (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
drewhammond authored Jan 29, 2023
1 parent 1ab1f4a commit 4a4e892
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/app/ui/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,17 @@ func (s *Service) RegisterRoutes() {
router.GET("/policy-groups", s.getPolicyGroups)
router.GET("/policy-groups/:name", s.getPolicyGroup)

router.GET("/assets/*", ViteHandler())
router.GET("/assets/*", ViteHandler(), CacheControlMiddleware)
}
}

// CacheControlMiddleware adds Cache-Control headers to static assets so that browsers can cache them
// for subsequent requests. Note that this should only be used on unique filenames such as those generated
// by the build process.
func CacheControlMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
c.Response().Header().Add(echo.HeaderCacheControl, "public,max-age=31536000,immutable")
return next(c)
}
}

Expand Down

0 comments on commit 4a4e892

Please sign in to comment.