.NET项目中Chrome未利用静态文件缓存的问题求助
IIS下.NET项目Chrome静态文件缓存异常排查
在基于IIS的.NET项目中,出现Chrome浏览器忽略部分静态文件缓存指令,但Firefox可正常从缓存加载文件的问题。
web.config相关配置片段
<location path="Scripts"> <system.web> <authorization> <allow users="*" /> </authorization> </system.web> <system.webServer> <staticContent> <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="100.00:00:00" /> </staticContent> </system.webServer> </location>
ASPX中静态文件引用示例
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> <link href="/Themes/General/css/ant.css" rel="stylesheet" type="text/css"/> <link href="../Scripts/vue/Components/css/app2.css" rel="stylesheet" type="text/css" /> </asp:Content>
异常现象
- Chrome网络流量显示,首次请求响应头已包含预期缓存指令,但后续部分带正确Cache-Control的JS、CSS仍从服务器获取
- 这些重复请求的资源Etag未变化、Last-Modified时间早于请求时间
- 页面共180次请求,仅70%从Chrome内存缓存加载
已尝试无效的方案
- 添加
immutable缓存指令 - 降低
cacheControlMaxAge时长 - 对静态文件进行压缩处理
- 在多环境、多设备上测试,问题均未解决
恳请提供排查思路或解决方案。
内容的提问来源于stack exchange,提问作者itay regev
相关产品推荐
相关产品推荐

