I'd like to set different cache-control header values for my js,css and html files. I know about the option to set it on a per-folder basis but my app has html and js files in the same folder.
Is it even possible in IIS ?
This is possible in IIS 7+ using IIS outbound rewrite rules. Eg. if you want to invalidate all .html pages, create the following outbound rule (after installing the IIS rewrite module) in the outboundRules section of the web.config:
<outboundRules>
<rule name="AdjustCacheForHTMLPages" preCondition="IsHTMLFile">
<match serverVariable="RESPONSE_Cache-Control" pattern=".*" />
<action type="Rewrite" value="no-cache, no-store, must-revalidate" />
</rule>
<preConditions>
<preCondition name="IsHTMLFile">
<add input="{REQUEST_FILENAME}" pattern=".*\.html" />
</preCondition>
</preConditions>
</outboundRules>
The answer by @jotap will only work for file requests that end in ".html". I needed it to work for the content type, too:
<outboundRules>
<rule name="AdjustCacheForHTMLPages" preCondition="IsHTML">
<match serverVariable="RESPONSE_CACHE-CONTROL" pattern=".*" />
<action type="Rewrite" value="no-cache, no-store, must-revalidate" />
</rule>
<preConditions>
<preCondition name="IsHTML" logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}" pattern="\.html$" />
<add input="{RESPONSE_CONTENT-TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With