问题描述:最近在给甲方爸爸做一个公众号的移动端项目,每周都会去服务器更新新的功能。但是由于微信自带的缓存功能,导致服务器重启后,还是原来的页面。每次都让甲方爸爸清除缓存,体验总归是不太好的嘛~~~
缓存问题,没有什么好的解决方案,只能一步一步优化。
1,入口文件index.html meta优化
<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Cache" content="no-cache">
2、打包的时候 加版本号 或者时间戳,目的区分路径
3、在nginx 中,把入口文件,缓存给清了
// nginx端配置
location = /index.html {
add_header Cache-Control "no-cache, no-store";
# add_header Cache-Control no-store;
# add_header Pragma no-cache;
}
expires 期限 可以用于设定网页的到期时间。一旦网页过期,必须到服务器上重新传输。
expires 30s;
add_header Cache-Control no-store;
4、通过在url的链接上加入时间戳或者版本号,当请求同一页面,如果url后的参数不同,就会重新调取页面