网站Nginx设置首页不缓存是否影响移动端体验?
1. 缓存设置对比
配置方案 | Nginx规则示例 | 移动端影响 |
---|---|---|
完全禁用缓存 | add_header Cache-Control "no-store"; |
首屏加载慢,但数据绝对新鲜 |
短时间缓存 | add_header Cache-Control "max-age=300"; |
平衡速度和实时性 |
按设备区分 | map $http_user_agent $cache_type { default "no-cache"; ~Mobile "max-age=3600"; } |
移动端缓存更久 |
2. 优化建议
- 动态内容:首页API接口禁用缓存,静态资源(CSS/JS)长期缓存
- 解决方案:
nginx
location = /index.html { add_header Cache-Control "no-cache"; # 首页HTML不缓存 } location ~* \.(jpg|css|js)$ { expires 365d; # 静态资源缓存1年 }
更新时间:2025-06-21 23:20:06
上一篇:网站首页文件被改如何查看日志?