vuepress 浏览器加载缓存,总是显示旧页面,无法自动刷新数据的解决方法

vuepress 采用多页面形式,每个md文件在打包时,都会被转为一个html页面;而浏览器默认会缓存页面,导致更新的页面必须手动刷新才行

对于更新较为频繁的文档

  • 全局可在config.js里设置

参考文档:

https://vuepress.github.io/zh/reference/config.html#head

https://vuepress.github.io/zh/reference/frontmatter.html#description

js 复制代码
export default defineUserConfig({
  ...
  head: [
    ["meta", {"http-equiv": "Pragma", content: "no-cache"}],
    ["meta", {"http-equiv": "Cache-Control", content: "no-cache"}],
    ["meta", {"http-equiv": "Expires", content: "0"}]
  ],
})
  • 单页面可以按Frontmatter语法要求在相应md文件设置
md 复制代码
---
head:
  - - meta
    - http-equiv: Pragma
      content: no-cache
    - http-equiv: Cache-Control
       content: no-cache
    - http-equiv: Expires
       content: 0
---
相关推荐
前端Hardy10 小时前
干掉 Virtual DOM?尤雨溪开始"强推" Vapor Mode?
vue.js·vue-router
Mr_li10 小时前
给 Vue 开发者的 uni-app 快速指南
vue.js·uni-app
icebreaker13 小时前
Weapp-vite:原生模式之外,多一种 Vue SFC 选择
前端·vue.js·微信小程序
icebreaker13 小时前
重走 Vue 长征路 Weapp-vite:编译链路与 Wevu 运行时原理拆解
前端·vue.js·微信小程序
wuhen_n13 小时前
代码生成:从AST到render函数
前端·javascript·vue.js
wuhen_n13 小时前
AST转换:静态提升与补丁标志
前端·javascript·vue.js
destinying14 小时前
性能优化之实战指南:让你的 Vue 应⽤跑得飞起
前端·javascript·vue.js
徐小夕15 小时前
JitWord Office预览引擎:如何用Vue3+Node.js打造丝滑的PDF/Excel/PPT嵌入方案
前端·vue.js·github
SuperEugene17 小时前
后台权限与菜单渲染:基于路由和后端返回的几种实现方式
前端·javascript·vue.js