diff --git a/docs/SERVICES.md b/docs/SERVICES.md index d0c4fcf..fd21c46 100644 --- a/docs/SERVICES.md +++ b/docs/SERVICES.md @@ -176,3 +176,19 @@ app/lib/ client.ts # getMinioClient, uploadBuffer, generateObjectKey index.ts ``` + +## 缓存与部署更新 + +项目已配置 `Cache-Control: no-store, no-cache`,部署后用户应能立即看到更新。若使用 **Cloudflare**,还需在控制台调整: + +### Cloudflare 控制台设置 + +1. **Caching → Configuration** + - **Caching Level**:选 `Standard` 或 `Bypass`(开发/频繁更新时) + - **Browser Cache TTL**:选 `Respect Existing Headers`,以遵循源站 `Cache-Control` + +2. **Caching → Cache Rules**(可选) + - 为 `/*` 添加规则:`Cache eligibility` = Bypass,或 `Edge TTL` = 0 + +3. **DNS** + - 记录 **TTL**:设为 `1`(Auto)或 `60` 秒,加快 DNS 变更生效 diff --git a/next.config.ts b/next.config.ts index db9ee24..20e4381 100644 --- a/next.config.ts +++ b/next.config.ts @@ -4,6 +4,24 @@ const nextConfig: NextConfig = { experimental: { serverActions: { bodySizeLimit: "25mb" }, }, + async headers() { + const noCacheHeaders = [ + { + key: "Cache-Control", + value: "no-store, no-cache, must-revalidate, proxy-revalidate", + }, + { key: "Pragma", value: "no-cache" }, + { key: "Expires", value: "0" }, + ]; + return [ + { source: "/", headers: noCacheHeaders }, + { + // 排除 /_next/ 静态资源(含 hash 可长期缓存),其余页面禁用缓存 + source: "/:path((?!_next).*)", + headers: noCacheHeaders, + }, + ]; + }, }; export default nextConfig; diff --git a/public/_headers b/public/_headers new file mode 100644 index 0000000..1da3a29 --- /dev/null +++ b/public/_headers @@ -0,0 +1,6 @@ +# Cloudflare Pages 自定义响应头(若使用 Cloudflare 部署) +# 禁用缓存,部署后用户立即看到更新 +/* + Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate + Pragma: no-cache + Expires: 0