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

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

对于更新较为频繁的文档

  • 全局可在config.js里设置

参考文档:
https://vuepress.github.io/zh/reference/config.html#head
https://vuepress.github.io/zh/reference/frontmatter.html#description

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文件设置
---
head:
  - - meta
    - http-equiv: Pragma
      content: no-cache
    - http-equiv: Cache-Control
       content: no-cache
    - http-equiv: Expires
       content: 0
---

猜你喜欢

转载自blog.csdn.net/weixin_44539199/article/details/142579277
今日推荐