之前每次更新tool.chaozhi.hk的时候,总是要刷新两次才能生效,现在总算解决这个问题了。

找过很多META标签的设置,例如下面这些,都不管用。

1
2
3
4
<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Cache" content="no-cache">

vue-cli里的默认配置,css和js的名字都加了哈希值,所以新版本css、js和就旧版本的名字是不同的,不会有缓存问题。

但是把打包好的index.html放到服务器里去的时候,index.html这个文件是有缓存的,这需要在服务器Nginx里配置,不让index.html缓存。

Nginx 配置如下(供参考):

1
2
3
location = /index.html {
add_header Cache-Control "no-cache, no-store";
}