目录Vue项目打包后浏览器缓存vue打包更新后缓存总结vue项目打包后浏览器缓存 1、第一步需要在index.html中添加如下代码: <meta Http-equiv="p
1、第一步需要在index.html中添加如下代码:
<meta Http-equiv="pragram" content="no-cache">
<meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="expires" content="0">
2、第二步需要在vue.config.js中添加如下代码:
const path = require("path"); // 获取当前的时间戳
let timeStamp = new Date().getTime();
module.exports = {
filenameHashing: false, // 打包的时候不使用hash值.因为我们有时间戳来确定项目的唯一性了.
configurewebpack: { //重点
output: { // 输出重构 打包编译后的js文件名称,添加时间戳.
filename: `js/js[name].${timeStamp}.js`,
chunkFilename: `js/chunk.[id].${timeStamp}.js`,
}
},
CSS: { //重点.
extract: { // 打包后css文件名称添加时间戳
filename: `css/[name].${timeStamp}.css`,
chunkFilename: `css/chunk.[id].${timeStamp}.css`,
}
}
};
可在自己的配置文件中相对的写入以上代码
3、需要在Nginx中配置不去缓存index.html文件内容(nginx.conf中配置)
if ($request_filename ~* ^.*?.(html|htm)$) {
add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
}
需要服务器配置
nginx: 里面cache-control:no-cache,no-store
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: vue项目打包后浏览器缓存问题及解决
本文链接: https://www.lsjlt.com/news/200445.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-12
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0