鍍金池/ 問答/Java  Linux  網(wǎng)絡安全  網(wǎng)絡營銷  HTML/ vue spa nginx 如何配置,能夠讓index.html不緩存呢(微信公

vue spa nginx 如何配置,能夠讓index.html不緩存呢(微信公眾號),求解答。。真心感謝

spa是vue腳手架npm run build 出來的一套靜態(tài)資源
/home/nodeuser/apps/hcz-weichat/source/dist這個目錄存放著靜態(tài)資源

nginx配置文件如下

/etc/nginx/conf.d/hcz_weichat.conf

server {
    listen 80;
    server_name domain;
    
    location /favicon.ico {
        root /home/nodeuser/apps/hcz-weichat/source/dist;
    }

    location / {
        root /home/nodeuser/apps/hcz-weichat/source/dist;
        index index.html;
        try_files $uri /index.html;
    }
}
回答
編輯回答
喵小咪

配置webpack的output,給build出來的文件加上hash后綴。

filename: '[name].js?[hash]'
2017年8月13日 01:51
編輯回答
別傷我
# vue 的路由頁面
location / {
    add_header Cache-Control "no-cache, no-store";
    root    /root/html/dist;
    index    index.html index.htm;
    try_files $uri $uri/ /index.html;
}
# vue編譯后的靜態(tài)資源地址
location /static/ {
     root    /root/html/dist;
     # ToDo
}
2017年1月17日 14:10
編輯回答
我甘愿
location = /index.html {
    add_header Cache-Control "no-cache, no-store";
}

no-cache, no-store可以只設置一個
no-cache瀏覽器會緩存,但刷新頁面或者重新打開時 會請求服務器,服務器可以響應304,如果文件有改動就會響應200
no-store瀏覽器不緩存,刷新頁面需要重新下載頁面

2018年8月9日 09:37