admin管理员组

文章数量:1534187

问题场景:

        1.线上部署nginx直接指向前端文件路径,nginx核心配置如下:

location /front/ {
          try_files $uri $uri/ /front/index.html;
          root /root/html/front;
}

         2.前端每次发布新版时,通过微信浏览器访问原来链接 www.front/front/ 总是旧版代码,缓存时间很久。对发版造成严重影响

分析原因:

        因为微信浏览器缓存了www.front/front/ 目录下的index.html,css文件,js文件,非常顽固。

解决方案:

       1.改变访问链接www.front/front/?v=1123,这种方案线上环境基本不可行,只能在测试环境使用,因为用户端访问链接大部分情况都很难控制,不能通知所有用户去访问新链接

       2.修改nginx配置,设置www.front/front/ 不缓存,nginx配置如下

location /front/ {
          try_files $uri $uri/ /front/index.html;
          root /root/html/front;
          #kill 缓存
          add_header Last-Modified $date_gmt;
          add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
          if_modified_since off;
          expires off;
          etag off;
}

 

本文标签: 缓存入口浏览器页面js