明天的明天 永远的永远 未知的一切 我与你一起承担 ??

是非成败转头空 青山依旧在 几度夕阳红 。。。
随笔 - 1277, 文章 - 0, 评论 - 214, 阅读 - 320万
  博客园  :: 首页  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

vue index.html缓存解决

Posted on   且行且思  阅读(2116)  评论(0编辑  收藏  举报

Vue 项目的 index.html 文件在部署到生产环境时,很容易受到浏览器缓存影响,导致用户无法看到最新的页面。为了解决这个问题,有几种方法:

  1. 使用版本号:在构建项目时,设置打包后的文件名中包含版本号,比如 index.html?v=1.0,每次更新版本号即可避免缓存问题。

  2. 使用 meta 标签:在 index.html 的 head 标签中添加 meta 标签,设置不缓存页面,代码如下:

<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Cache" content="no-cache">

 

 3.使用 nginx 反向代理:在 nginx 配置文件中设置不缓存页面,代码如下:

复制代码
server {
        listen       80;
        server_name  test.exmaple.cn;
 
 
        location / {
                if ($request_filename ~* .*\.(?:htm|html)$)  ## 配置页面不缓存html和htm结尾的文件
                {
                   add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
                }
                root /web/;
                index index.html;
                try_files $uri $uri/ /index.html =404;
        }
}
复制代码

 

以上三种方法任选其一即可解决 Vue 项目 index.html 缓存问题。

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示