冷首访白屏的第二个真因:/contact 用 useSearchParams() 读 ?success,客户端组件里 这会让整页在预渲染时退化成 Suspense fallback(首访只看到「加载中…」,限速下 ~6s 才出内容)。 该参数只用于一次性成功提示 ⇒ 改为挂载后从 window.location 读并 replaceState 清理。 - /contact 冷首访 h1 可见:6.0s → 1.5s;HTML 73KB 含正文(此前只有外壳)。 - 新增 scripts/ops/warm-routes.mjs:按 sitemap 预热并断言全 200、第二遍 <1500ms 或 HIT; 本轮线上第二遍:非 200 = 0、>1500ms = 0。 - 全站冷首访复测:/ 827ms、/about 1652ms、/contact 1511ms、/products 917ms、 /services/software 922ms、/insights 1532ms。 - runbook:加发布前磁盘检查(≥2G)与「构建失败必须中止」;加 §4.0 预热步骤。 - 事故记录:第三次重建时服务器磁盘 99%,COPY 报 ENOSPC 而 up -d 仍执行(旧镜像被当已发布); 清理旧备份 1.8G + docker image prune 1.075G 后回到 81%,重建 015b6d75 成功。
40 lines
2.1 KiB
JavaScript
40 lines
2.1 KiB
JavaScript
import { chromium } from 'playwright';
|
|
const b = await chromium.launch();
|
|
const ctx = await b.newContext({ viewport:{width:1280,height:900} });
|
|
const p = await ctx.newPage();
|
|
const cdp = await ctx.newCDPSession(p);
|
|
await cdp.send('Network.enable');
|
|
await cdp.send('Network.setCacheDisabled', { cacheDisabled: true });
|
|
await cdp.send('Network.emulateNetworkConditions', { offline:false, latency:150, downloadThroughput: 900*1024/8, uploadThroughput: 400*1024/8 });
|
|
const t0 = Date.now();
|
|
const samples = [];
|
|
const seen = new Set();
|
|
p.on('response', r => { if (r.url().includes('/about')) seen.add(`${r.status()} ${r.url()}`); });
|
|
const nav = p.goto('https://www.novalon.cn/about', { waitUntil:'commit', timeout:90000 }).catch(()=>null);
|
|
for (let i=0;i<80;i++) {
|
|
const s = await p.evaluate(() => {
|
|
const h1 = document.querySelector('h1');
|
|
const html = document.documentElement;
|
|
// 找包住 main 的 motion wrapper 的 opacity
|
|
const main = document.querySelector('main');
|
|
let wrap = main?.parentElement, wrapOp = null;
|
|
while (wrap && wrap !== document.body) { const o = getComputedStyle(wrap).opacity; if (o !== '1') { wrapOp = o; break; } wrap = wrap.parentElement; }
|
|
return { t: Math.round(performance.now()),
|
|
body: document.body ? document.body.innerHTML.length : -1,
|
|
h1op: h1 ? Number(getComputedStyle(h1).opacity) : null,
|
|
wrapOp,
|
|
textLen: document.body ? (document.body.innerText||'').trim().length : -1 };
|
|
}).catch(()=>null);
|
|
if (s) samples.push(s);
|
|
await p.waitForTimeout(120);
|
|
if (s && s.h1op === 1 && s.textLen > 800) break;
|
|
}
|
|
await nav;
|
|
console.log('responses', JSON.stringify([...seen]));
|
|
const firstText = samples.find(s=>s.textLen>500);
|
|
const firstVisible = samples.find(s=>s.h1op===1 && s.textLen>800);
|
|
console.log('TTFB-ish 首个有文字样本:', firstText ? `${firstText.t}ms len=${firstText.textLen} wrapOp=${firstText.wrapOp} h1op=${firstText.h1op}` : 'none');
|
|
console.log('首个 h1 完全不透样本:', firstVisible ? `${firstVisible.t}ms` : 'none');
|
|
console.log('样本前 6 条:', JSON.stringify(samples.slice(0,6)));
|
|
await b.close();
|