azure - How can I apply <clientCache /> settings to a specific extension in IIS? -


i hosting web app on azure following web.config:

<?xml version="1.0" encoding="utf-8"?> <configuration>   <system.webserver>     <staticcontent>       <mimemap fileextension=".text" mimetype="text/plain" />       <clientcache cachecontrolcustom="public" cachecontrolmode="usemaxage" cachecontrolmaxage="7.00:00:00" />     </staticcontent>   </system.webserver> </configuration> 

this works vary cache age extension. set max age of .html files 1 day , max age of else 365 days. reason being of assets in html have filenames revved on change , served cdn, never need expire, html pages need fresh user can see new content.

i see <location> element allows filtering web.config specific locations, don't see way limit extensions.

please note don't require being able in web.config: means possible azure web app fine.

others have mentioned not possible suggest workaround job.
can take advantage of capabilities of url rewrite module creating outbound rule replace cache-control header of html files.

here's config.

<?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> 

a screenshot of test:

enter image description here


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -