解决Vue 3.0打包文件放在服务器后缓存问题
vue-cli里的默认配置,css和js的名字都加了哈希值,所以新版本css、js和就旧版本的名字是不同的,不会有缓存问题。
解决放方案
1、在入口文件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">

2、把打包好的index.html放到服务器里去的时候,index.html在服务器端可能是有缓存的,这个时候就需要在服务器配置不让缓存index.html
nginx 配置如下:
location = /index.html {
add_header Cache-Control "no-cache, no-store";
}
注意:no-cache浏览器会缓存,但刷新页面或者重新打开时 会请求服务器,服务器可以响应304,如果文件有改动就会响应200
no-store浏览器不缓存,刷新页面需要重新下载页面

浙公网安备 33010602011771号