nginx 部署前端項目,不緩存html文件,項目更新,不用手動刷新頁面


          location /xxxx{

                gzip on;
                gzip_min_length 1k;
               #gzip_buffers 4 16k;
                gzip_http_version 1.1;
                gzip_comp_level 4;
                gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/gif;
                gzip_vary off;
                gzip_disable "MSIE [1-6]\.";

                alias /html/xxxx/;
                index index.html;

               if ($request_filename ~* .*\.(?:htm|html)$)  ## 配置頁面不緩存
               {
                   add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
               }

        }


配置HTML文件不緩存后,每次更新項目,會重新請求頁面,而因為現在的前程工程也都需要打包,在打包工具會自動在文件名上加時間戳、哈希值,這樣一發新版時,只要客戶端請求了新版的html,里面引用的js/css/jpg等都已經換了路徑,肯定也就不會使用本地的緩存了

https://blog.csdn.net/yu12377/article/details/77875045


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM