前几天部署完项目遇到一个问题,编译的依赖都是有hash的,但访问的时候还是有缓存问题。通过排查发现是html的缓存导致,如下图
所以要解决这个问题就要让html禁止用缓存中获取,同时为了提升加载速度,依赖的js、css、png 依旧通过缓存获取
解决方案
通过Nginx配置实现 ,添加 add_header Cache-Control no-cache;
location ~^/test/*\.* {
access_log on;
access_log /var/log/nginx/nginx_access_cli_test.log ;
root /usr/share/nginx/html;
index index.html;
add_header Cache-Control no-cache;
try_files $uri $uri/ /kyc/index.html;
}