对于浏览器缓存,我想为web.config中的一个.js文件设置过期时间而不是整个js文件夹。为此,我尝试在How to configure static content cache per folder and extension in IIS7?的帮助下使用以下配置,但它不起作用:
<configuration>
<location path="compiled.js">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
</staticContent>
</system.webServer>
</location>
</configuration>
然后我尝试更改“location”属性中的路径,如下所示,但这对我也不起作用:
<configuration>
<location path="~/js/compiled.js">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
</staticContent>
</system.webServer>
</location>
</configuration>
有人可以帮我解决如何通过web.config为一个.js文件而不是整个文件夹设置缓存过期时间?
答案 0 :(得分:0)
对于单个文件,我们可以在web.config文件中设置缓存过期时间,如下所示:
<configuration>
<location path="js/compiled.js">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
</staticContent>
</system.webServer>
</location>
</configuration>
此外,我们可以使用不同的<location>
部分为不同的文件/文件夹指定缓存设置。