之前每次發版vue項目的時候,總是要強制刷瀏覽器才能生效,現在總算解決這個問題了。
vue-cli里的默認配置,css和js的名字都加了哈希值,所以新版本css、js和就舊版本的名字是不同的,不會有緩存問題。
但是把打包好的index.html放到服務器里去的時候,index.html在服務器端可能是有緩存的,這需要在服務器配置不讓緩存index.html
解決方法如下:
前端在index.html中添加:
<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">
nginx 配置如下:
location = /index.html {
add_header Cache-Control "no-cache, no-store";
}