关于vue.js:vue打包线上报错

4次阅读

共计 586 个字符,预计需要花费 2 分钟才能阅读完成。

以 vue 为例,vue 在打包的时候,css 和 js 名字都加了哈希值,所以改变后打包生成的 js 和 css 是惟一的,页面申请的是新资源,不会有缓存问题。然而入口文件 index.html 会因为缓存造成更新问题,如果咱们更新了,然而浏览器应用的是缓存,就会呈现问题。所以须要对入口文件设置不使缓存,须要每次去服务器验证文件是否批改

    应用 nginx 反向代理,在 nginx.conf 文件的对应 server 中设置,目前我本人实际出的可行的一种写法是:

    server {

        listen       80;

        server_name  域名;

        root   文件目录;

        index  index.html;

        location / {// 不加这一句,会呈现 nginx 欢送页面,无奈正确加载资源

          try_files $uri /index.html;

        }

        location ~ .*.(html)$ {// 对 html 文件限度缓存

          add_header Cache-Control no-store;  // 不缓存

         // 或者用 add_header Cache-Control no-cache; 代替下面那一句,协商缓存

          add_header Pragma no-cache;

        }

}

正文完
 0