mirror of
https://github.com/usememos/memos.git
synced 2025-12-17 14:19:17 +08:00
fix(server): reduce static asset cache to prevent stale files after redeploy
Changed Cache-Control max-age from 7 days to 1 hour with immutable directive. This prevents users from experiencing blank pages or JS errors when accessing frequently redeployed instances (e.g., demo environments) where old cached assets may reference files that no longer exist after redeployment. Since Vite generates content-hashed filenames, the immutable directive prevents unnecessary revalidation while the shorter cache duration ensures fresh assets are served within an hour of redeployment. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
2197178dd7
commit
91a7e927a5
1 changed files with 6 additions and 2 deletions
|
|
@ -39,8 +39,12 @@ func (*FrontendService) Serve(_ context.Context, e *echo.Echo) {
|
|||
if c.Path() == "/" || c.Path() == "/index.html" {
|
||||
return false
|
||||
}
|
||||
// Set Cache-Control header to allow public caching with a max-age of 7 days.
|
||||
c.Response().Header().Set(echo.HeaderCacheControl, "public, max-age=604800") // 7 days
|
||||
// Set Cache-Control header for static assets.
|
||||
// Since Vite generates content-hashed filenames (e.g., index-BtVjejZf.js),
|
||||
// we can cache aggressively but use immutable to prevent revalidation checks.
|
||||
// For frequently redeployed instances, use shorter max-age (1 hour) to avoid
|
||||
// serving stale assets after redeployment.
|
||||
c.Response().Header().Set(echo.HeaderCacheControl, "public, max-age=3600, immutable") // 1 hour
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue