看到 X-Cache: HIT 就认为 Magento 性能没有问题,是常见误判。Varnish 只说明主响应命中了某个缓存对象;页面可交互时间还受 private content、ESI、GraphQL/AJAX、图片、JavaScript 和第三方标签影响。
先把主文档时间单独量出来
curl -sk -o /dev/null -w 'code=%{http_code} dns=%{time_namelookup} connect=%{time_connect} start=%{time_starttransfer} total=%{time_total}
' https://shop.example.com/category.html
curl -skI https://shop.example.com/category.html | egrep -i 'age|x-cache|cache-control|x-magento-cache-debug|via'
TTFB 很低而浏览器仍慢,问题大概率不在 PHP 生成主页面。TTFB 仍高时,要确认所谓 HIT 是否来自正确层、是否发生 ESI 回源,或边缘节点到用户的网络耗时。
列出首屏之后发起的动态请求
在浏览器 Network 按开始时间排序,关注 customer/section/load、推荐接口、搜索建议、第三方支付与统计请求。任一同步等待都可能让加载动画持续。
curl -sk -o /dev/null -w '%{time_starttransfer} %{time_total}
' 'https://shop.example.com/customer/section/load/?sections=cart,customer'
grep -Rni "customerData.reload|section/load" app/design app/code | head -n 40
自定义组件每次页面加载都强制 reload private section,会绕过主页面缓存优势。应检查 sections.xml 是否把无关 action 绑定到大量 section。
确认 Varnish 对不同访问条件的表现
for i in 1 2 3; do
curl -skI https://shop.example.com/category.html | egrep -i 'age|x-cache|set-cookie';
done
curl -skI -H 'Cookie: PHPSESSID=test' https://shop.example.com/category.html | egrep -i 'age|x-cache|cache-control'
匿名、带会话 Cookie、不同 Store 和货币的缓存键可能不同。不要只用一次无 Cookie 请求代表真实用户。
用浏览器 Performance 找主线程瓶颈
如果所有网络请求都快,但页面迟迟不能点击,记录 Performance trace,查长任务、重复 layout 和大型 bundle 执行。此时再调 Varnish TTL 没有帮助,应拆分前端模块、延迟非关键脚本并减少首屏 DOM。
最终报告应分别给出主文档 TTFB、最大动态请求耗时、静态资源体积和主线程长任务,而不是一句“缓存已命中”。这样才能把后端缓存、接口和前端执行分给正确负责人。

