由于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表示让现有缓存立即失效

相关文章:

  • 2021-05-29
  • 2021-12-08
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-16
  • 2021-11-30
  • 2021-11-30
  • 2022-02-05
  • 2021-12-06
  • 2021-09-01
  • 2021-04-21
相关资源
相似解决方案