From ebf13c4dffc9d262855534c0bcde7c3ff15ee89d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=80=92=E9=9C=89=E7=8B=90=E7=8B=B8?= Date: Wed, 9 Apr 2025 22:22:03 +0800 Subject: [PATCH] chore: caching resource files accelerates second requests (#4614) * cache assets files * Apply suggestions from code review * Update server/router/frontend/frontend.go * Update server/router/frontend/frontend.go --------- Co-authored-by: Johnny --- server/router/frontend/frontend.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/router/frontend/frontend.go b/server/router/frontend/frontend.go index 3920423b..a3b499c2 100644 --- a/server/router/frontend/frontend.go +++ b/server/router/frontend/frontend.go @@ -31,7 +31,12 @@ func NewFrontendService(profile *profile.Profile, store *store.Store) *FrontendS func (*FrontendService) Serve(_ context.Context, e *echo.Echo) { apiSkipper := func(c echo.Context) bool { - return util.HasPrefixes(c.Path(), "/api", "/memos.api.v1") + if util.HasPrefixes(c.Path(), "/api", "/memos.api.v1") { + return true + } + // Set Cache-Control header to allow public caching with a max-age of 30 days (in seconds). + c.Response().Header().Set(echo.HeaderCacheControl, "public, max-age=2592000") + return false } // Route to serve the main app with HTML5 fallback for SPA behavior.