From a04abb0cc80cbc9684b6b69a2d0385effec1947b Mon Sep 17 00:00:00 2001 From: richjohnrambo Date: Fri, 28 Aug 2026 01:42:14 +0800 Subject: [PATCH] fix: set admin frontend cache headers --- server/internal/logic/hook/init.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/server/internal/logic/hook/init.go b/server/internal/logic/hook/init.go index 8bc315f..3e97b5d 100644 --- a/server/internal/logic/hook/init.go +++ b/server/internal/logic/hook/init.go @@ -8,6 +8,7 @@ package hook import ( "github.com/gogf/gf/v2/net/ghttp" "hotgo/internal/service" + "strings" ) type sHook struct { @@ -22,10 +23,23 @@ func New() *sHook { } func (s *sHook) BeforeServe(r *ghttp.Request) { - + s.setAdminStaticCacheHeader(r) } func (s *sHook) AfterOutput(r *ghttp.Request) { s.accessLog(r) s.lastAdminActive(r) } + +func (s *sHook) setAdminStaticCacheHeader(r *ghttp.Request) { + path := r.URL.Path + if path == "/admin" || path == "/admin/" || path == "/admin/index.html" || path == "/admin/app.config.js" { + r.Response.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") + r.Response.Header().Set("Pragma", "no-cache") + r.Response.Header().Set("Expires", "0") + return + } + if strings.HasPrefix(path, "/admin/assets/") { + r.Response.Header().Set("Cache-Control", "public, max-age=31536000, immutable") + } +}