我想要能够应用缓存到我的网站上的静态文件。
我希望缓存只适用于特定的文件扩展名,但我不能百分之百地肯定要添加到我的web.config文件中的语法。
到目前为止,这就是我所拥有的:
<staticContent>
<remove fileExtension=".svg" />
<remove fileExtension=".jpg" />
<remove fileExtension=".png" />
<remove fileExtension=".gif" />
<remove fileExtension=".css" />
<remove fileExtension=".js" />
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml"/>
<mimeMap fileExtension=".jpg" mimeType="image/jpg"/>
<mimeMap fileExtension=".png" mimeType="image/png"/>
<mimeMap fileExtension=".gif" mimeType="image/gif"/>
<mimeMap fileExtension=".css" mimeType="text/css"/>
<mimeMap fileExtension=".js" mimeType="text/javascript"/>
</staticContent>我认为这将适用于具有以下扩展名的静态文件,这是正确的吗?
看起来,配置中的clientCache节点并不直接绑定到mimeMap语句。我不一定希望clientCache处理指定列表之外的文件。
此外,这种方法有什么‘棘手’,我应该警惕吗?
谢谢你的帮助。
网站详情:
发布于 2019-08-12 02:59:31
可以使用以下代码应用客户端缓存控制设置:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".text" mimeType="text/plain" />
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
</staticContent>
<rewrite>
<outboundRules>
<rule name="RewriteCacheControlForHTMLFiles" preCondition="FileEndsWithHtml">
<match serverVariable="RESPONSE_Cache_Control" pattern=".*" />
<action type="Rewrite" value="max-age=86400" />
</rule>
<preConditions>
<preCondition name="FileEndsWithHtml">
<add input="{REQUEST_FILENAME}" pattern="\.html$" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>注意:使用您的文件扩展名。
您也可以使用location标记来完成此操作,但为此,您需要将特定的文件扩展名文件移动到另一个文件夹--将此设置应用于该文件夹。
<configuration>
<!-- Note the use of the 'location' tag to specify which
folder this applies to-->
<location path="images">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
</staticContent>
</system.webServer>
</location>
</configuration>https://stackoverflow.com/questions/57425432
复制相似问题