Vue/cli2 || /cli3部署上线清理浏览器缓存

问题描述:项目(vue /cli2 || vue /cli3) 部署上线用浏览器打开后依旧是上一个版本

问题原因:浏览器的缓存机制(分为强缓存和协商缓存)
强缓存:不在客户端存储资源,始终去原始服务器获取资源
协商缓存:向后端发起请求,看服务器资源是否更新,如果没有更新就返回304,如果更新了就返回200
no-cacheno-store 都是 HTTP 协议头 Cache-Control 的值。区别是:
no-store
彻底禁用缓存,所有内容都不会被缓存到缓存或临时文件中。
no-cache
可以在客户端存储资源,每次都必须去服务端做新鲜度校验,来决定从服务端获取新的资源(200)还是使用客户端缓存(304)。也就是所谓的协商缓存
除了 no-cacheno-storeCache-Control 头的取值还有:
public
所有内容都将被缓存(客户端和代理服务器都可缓存)
private
内容只缓存到私有缓存中(仅客户端可以缓存,代理服务器不可缓存)
max-age=xxx
缓存的内容将在 xxx 秒后失效,这个选项只在 HTTP1.1 可用,并如果和 Last-Modified 一起使用时,优先级较高。

一、修改根目录index.html,添加以下代码

于 HEAD 标签内直接添加 META 标签:
1.)本人所在项目采用得这个

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

2.)如果不想彻底禁止缓存可以采用下面的

<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="expires" content="0" />

二、nginx设置不缓存 html

(nginx设置后,每次刷新页面加载时间太长,所以我所在项目未使用)
1.)在nginx.conf文件做设置:增加add_header Cache-Control "no-cache, no-store

location = /index.html {
   
   
	root	 /usr/webkit/dist;
    add_header Cache-
run `npm fund` for details fanwei@192 eam % npm install @vue/cli-service@latest --save-dev npm WARN ERESOLVE overriding peer dependency npm WARN While resolving: eam@1.0.5 npm WARN Found: @vue/cli-service@4.5.19 npm WARN node_modules/@vue/cli-service npm WARN peer @vue/cli-service@"^3.0.0 || ^4.0.0-0" from @vue/cli-plugin-babel@4.5.19 npm WARN node_modules/@vue/cli-plugin-babel npm WARN dev @vue/cli-plugin-babel@"~4.5.0" from the root project npm WARN 3 more (@vue/cli-plugin-router, @vue/cli-plugin-vuex, the root project) npm WARN npm WARN Could not resolve dependency: npm WARN peer @vue/cli-service@"^3.0.0 || ^4.0.0-0" from @vue/cli-plugin-babel@4.5.19 npm WARN node_modules/@vue/cli-plugin-babel npm WARN dev @vue/cli-plugin-babel@"~4.5.0" from the root project npm WARN ERESOLVE overriding peer dependency npm WARN While resolving: eam@1.0.5 npm WARN Found: @vue/cli-service@4.5.19 npm WARN node_modules/@vue/cli-service npm WARN peer @vue/cli-service@"^3.0.0 || ^4.0.0-0" from @vue/cli-plugin-babel@4.5.19 npm WARN node_modules/@vue/cli-plugin-babel npm WARN dev @vue/cli-plugin-babel@"~4.5.0" from the root project npm WARN 3 more (@vue/cli-plugin-router, @vue/cli-plugin-vuex, the root project) npm WARN npm WARN Could not resolve dependency: npm WARN peer @vue/cli-service@"^3.0.0 || ^4.0.0-0" from @vue/cli-plugin-router@4.5.19 npm WARN node_modules/@vue/cli-plugin-router npm WARN @vue/cli-plugin-router@"^4.5.19" from @vue/cli-service@4.5.19 npm WARN 1 more (the root project) npm WARN ERESOLVE overriding peer dependency npm WARN While resolving: eam@1.0.5 npm WARN Found: @vue/cli-service@4.5.19 npm WARN node_modules/@vue/cli-service npm WARN peer @vue/cli-service@"^3.0.0 || ^4.0.0-0" from @vue/cli-plugin-babel@4.5.19 npm WARN node_modules/@vue/cli-plugin-babel npm WARN dev @vue/cli-plugin-babel@"~4.5.0" from the root project npm WARN 3 more (@vue/cli-plugin-router, @vue/cli-plugin-vuex, the root project) npm WARN npm WARN Could not
最新发布
03-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值