环境:
前端单页面(Vue) + Nginxcss
问题:
http://xxx.com/a/ 访问会跳转到 http://xxx.com/a/Index 下,代码有更新访问 http://xxx.com/a/Index 完整连接index.html加载是最新的,访问 http://xxx.com/a/ 仍是读取的disk cache的内容,致使加载的页面不是最新的。使得用户不清理缓存展现的内容是错误的。html
解决方法:
nginx下配置no-cache、no-store前端
示例:nginx
location /a { add_header Cache-Control 'no-cache, no-store, must-revalidate,proxy-revalidate, max-age=0'; }
no-cache:能够在本地缓存,能够在代理服务器缓存,可是这个缓存要服务器验证才能够使用。index.html没有改变,浏览器状态码是304。chrome
no-store: 本地和代理服务器都不缓存,每次都从服务器获取。index.html状态码始终是200。浏览器
must-revalidate: 缓存必须在使用以前验证旧资源的状态,而且不可以使用过时资源。表示若是页面过时,则去服务器进行获取。缓存
proxy-revalidate: 与must-revalidate做用相同,但它仅适用于共享缓存(例如代理),并被私有缓存忽略。服务器
max-age=<seconds>: 设置缓存存储的最大周期,超过这个时间缓存被认为过时(单位秒)。与Expires相反,时间是相对于请求的时间。max-age会覆盖掉Expires。spa
在chrome network查看请求资源的时候,发现浏览器缓存有3中状况。.net
参考:
https://www.zhihu.com/question/64201378
https://blog.csdn.net/zs343961443/article/details/87258217