Skip to content

vue项目浏览器缓存解决 #12

@imondo

Description

@imondo

浏览器缓存statusCode区别

  • 200 OK (from cache)* 是直接点击链接访问,输入网址按回车访问也能触发;浏览器没有跟服务器确认,直接用了浏览器缓存;

  • 304 Not Modified 是刷新页面时触发,或是设置了长缓存、但 Entity Tags 没有移除时触发;是浏览器和服务器确认了一次缓存的有效性,再使用缓存,多一次确认

vue项目首页index.html强制去掉缓存

// index.html
<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">

// nginx
location /demo{
   add_header Cache-Control 'private, no-store, max-age=0';
   alias  /opt/nginx-front/test/demo;
   index  index.html;
   try_files $uri $uri/ /demo/index.html;
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions