Advertisement

搭建Nginx服务以优化微信浏览器的缓存性能

阅读量:

问题描述

微信公众号或H5网站在发布内容后始终显示旧内容无法更新;当登录token失效时也无法执行相应的JS退出操作;其根本原因是微信浏览器 inherent cache mechanism 的结果。最初尝试过在网站链接中添加version号等手段均无效;针对nginx部署项目提供了如下解决方案

解决方案

为在nginx配置文件xxx.conf中添加相关代码用于清除缓存并禁用缓存机制。(其中$root应替换为实际站点源码目录)

复制代码
    location ~* ^.+\.(jpg|jpeg|png|ico|css|js)$ {
    root $root;
    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;
    }

全部评论 (0)

还没有任何评论哟~