# html静态资源不缓存
html资源如果缓存的话,项目升级后如果有更新前端资源,浏览器需要主动清理缓存才能是升级后的前端介质生效。在 Nginx 上配置不缓存 HTML 文件即可解决此问题。
Nginx具体配置如下:
location / {
root ${userDir}${appDir};
# 配置页面不缓存html和htm结尾的文件
if ($request_filename ~* .*\.(?:htm|html)$)
{
add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
}
if ($request_filename ~* /remoteEntry\.js$)
{
add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
}
index index.html index.htm;
try_files $uri /index.html;
}