vue开发解决缓存问题-nginx

2,124 阅读1分钟

修改default.conf文件

location / {
        root   /usr/share/nginx/html/school-static;
        index  index.html index.htm;
        // 添加
        if ($request_filename ~* .*\.(?:htm|html)$)
        {
            add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
        }
        if ($request_filename ~* .*\.(?:js|css)$)
        {
            expires      7d;
        }
        if ($request_filename ~* .*\.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm)$)
        {
            expires      7d;
        }
    }

修改public/index.html文件

// 添加
<meta http-equiv="pragram" content="no-cache">
<meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate">