美文网首页
微信浏览器index.html入口文件被缓存的问题

微信浏览器index.html入口文件被缓存的问题

作者: yangganboy | 来源:发表于2022-04-14 17:50 被阅读0次

在某些场景下微信根本就不检查,网页是否更新。

脏话。。。

可以通过在nginx里面设置html文件 expires -1;

这会影响其他浏览器或者有些情况我们无法做这个配置,我们可以使用以下js代码实现强制刷新html

<script> (function(){ if(navigator.userAgent.indexOf('WeChat')!=-1){ var href=window.location.href; if(href.indexOf('?_v=')==-1&&href.indexOf('&_v=')==-1){ if(href.indexOf('#')!=-1){ href=href.substring(href); } if(href.indexOf('?')!=-1){ window.location.href=href+"&_v="+new Date().getTime()+window.location.hash; }else{ window.location.href=href+"?_v="+new Date().getTime()+window.location.hash; } } } })(); </script>

对已经被缓存的网页无效。可以先在公众号菜单等位置给地址加一个版本号参数

相关文章

网友评论

      本文标题:微信浏览器index.html入口文件被缓存的问题

      本文链接:https://www.haomeiwen.com/subject/rwtxertx.html