vue-cli4.0 项目发布浏览器缓存问题

每次vue项目部署之后,新增的需求和改的bug都不起作用,每次都需要清理一下浏览器缓存才能使用

用户体验感太差

  1. 修改请求头
  2. 修改服务器ng配置
  3. webpack打包时添加时间戳

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">

在Chrome中,设置Cache-Control为no-store,可以防止页面被放在cache中,这样可以直接去请求服务器,但是Cache-Control为no-cache,对Chrome不能起到作用,但是对于IE浏览器而言,设置Cache-Control为no-store和no-cache均可以发挥作用,同时对于搜狗和Firefox浏览器而言,将Cache-Control为no-store均可以达到不设置缓存的目的,一定要注意

2.在ng/conf/nginx.conf配置文件,让index.html不再缓存,记得重启ng

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

3.webpack配置,让js。css文件携带时间戳

const path = require(“path”); // 获取当前的时间戳
let timeStamp = new Date().getTime();
module.exports = {
	filenameHashing:false, // 打包的时候不使用hash值.因为我们有时间戳来确定项目的唯一性了.
   // 
   configureWebpack: {    //重点
	    output: { // 输出重构 打包编译后的js文件名称,添加时间戳.
             filename: `js[name].${ timeStamp }.js`,
               chunkFilename: `js[name].${ timeStamp }.js`,
		}
	},
	css: { //重点.
		extract:{ // 打包后css文件名称添加时间戳
		 	filename:`css/[name].${ timeStamp }.css`,
		 	chunkFilename:`css/[name].${ timeStamp }.css`,
		}
	}
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值