JavaScript
主页 > 网络编程 > JavaScript >

前端发布缓存导致白屏几种解决方案

2025-05-13 | 佚名 | 点击:

一、 核心配置优化(前提是访问网站的请求能抵达服务器)

方案一:前端项目设置全局不缓存方案

方案二: 首页index.html资源缓存修正,禁制index.html文件缓存

1

2

3

4

5

6

7

8

9

10

11

12

13

server {

    listen 8080;

    root /var/www/web/;

    location /index.html {

        add_header Cache-Control "no-cache, no-store, must-revalidate, private";

        add_header Pragma "no-cache";

        add_header Expires "0";

        try_files $uri /index.html;

    }

    location / {

        try_files $uri $uri/ /index.html;

    }

}

方案三: 首页 index.html 资源添加 ETag和Last-Modified 参数

1

2

3

4

5

6

7

8

9

10

11

12

13

14

server {

    listen 8080;

    root /var/www/web/;

    location /index.html {

        etag on;

        if_modified_since exact;

        add_header Cache-Control "public, max-age=0";

        expires modified +1y;

        try_files $uri /index.html;

    }

    location / {

        try_files $uri $uri/ /index.html;

    }

}

二、 jenkins发布流程优化方案

三、 使用版本号方案

通过后端更新版本号

原文链接:
相关文章
最新更新