由於vue在打包時會自動在更改過的js文件上加上hash過的后綴,所以js一般在上線后都會更新。但是index.html不會,由於index.html被緩存而飲用了老的js文件,如果這些老的文件在微信端被緩存那用用戶登上去看的時候就不會發現有更新。為了讓最新的應用對每個用戶立即生效,要做的是 1. 馬上丟棄原有緩存 2. 讓html不緩存。在nginx上配置可以解決
location / {
try_files $uri $uri/ /index.html;
index index.html;
add_header Cache-Control "no-store,max-age=0";
}
location ~* \.(html)$ {
access_log off;
add_header Cache-Control "no-store,max-age=0"; }
location ~* \.(css|js|png|jpg|jpeg|gif|gz|svg|mp4|ogg|ogv|webm|htc|xml|woff)$ {
access_log off;
add_header Cache-Control max-age=604800;
}
這里注意光加上no-store並不能完全解決問題,no-store表示response不緩存,但如果原先已經有緩存了那還是有問題,max-age=0表示讓現有緩存立即失效
