perf: 图片 PNG 全量转 WebP + 图片缓存头,首屏体积省 92% 提速
- hotels/ 154 张 PNG(186MB) 转 q80 WebP(15MB),省 92%,原 PNG 保留作备份 - data.json/data.seed.json/assets JS 共 1548 处图片引用 .png→.webp - server.js: /hotels/ 图片 Cache-Control 改 public,max-age=3600(原一刀切 no-cache,每次访问全量重下) Co-Authored-By: Claude <noreply@anthropic.com>
这个提交包含在:
@@ -147,9 +147,12 @@ function serveStatic(req, res, urlPath) {
|
||||
const headers = { 'Content-Type': MIME[ext] || 'application/octet-stream' };
|
||||
const abs = p.startsWith('/assets/');
|
||||
const isHotels = p.startsWith('/hotels/');
|
||||
// 无构建步骤、资源为手改(文件名哈希不随内容变),不用 immutable 长缓存,避免改动不生效
|
||||
if (abs) headers['Cache-Control'] = 'no-cache';
|
||||
else if (isHotels || ext === '.json') headers['Cache-Control'] = 'no-cache';
|
||||
// 缓存策略(2026-08-19 提速优化):
|
||||
// - 酒店图片(hotels/):内容大体稳定、单图曾达 2-3MB,是首屏慢的主因;
|
||||
// 给 1 小时缓存+过期重校验——回头客秒开,后台改图最多 1 小时后全网生效(不用 immutable 是怕改图不生效)。
|
||||
// - assets/ 构建产物:data.json 注入在服务端,文件名哈希不随内容变,保守 no-cache。
|
||||
// - data.json / index.html / 其余:内容常变,保持 no-cache 实时。
|
||||
if (isHotels) headers['Cache-Control'] = 'public, max-age=3600, must-revalidate';
|
||||
else headers['Cache-Control'] = 'no-cache';
|
||||
res.writeHead(200, headers);
|
||||
fs.createReadStream(file).pipe(res);
|
||||
|
||||
在新工单中引用
屏蔽一个用户