Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable caching of single page application HTML file served through IIS?

I have a single page application (angular-js) which is served through IIS. How do I prevent caching of HTML files? The solution needs to be achieved by changing content within either index.html or the web.config, as access to IIS through a management console is not possible.

Some options I am currently investigating are:

  • web.config caching profiles - http://www.iis.net/configreference/system.webserver/caching
  • web.config client cache - http://www.iis.net/configreference/system.webserver/staticcontent/clientcache
  • meta tags - Using <meta> tags to turn off caching in all browsers?

IIS is version 7.5 with .NET framework 4

like image 754
Andrew Avatar asked Oct 28 '14 04:10

Andrew


People also ask

How do I stop html from caching?

Here's how... When you're in Google Chrome, click on View, then select Developer, then Developer Tools. Alternatively, you can right click on a page in Chrome, then click Inspect. Click on the Network tab, then check the box to Disable cache.

How do I disable cache in API?

Just use the Cache-Control: no-cache header. Implement it as delegating-Handler and make sure your header is applied (with MS Owin Implementation hook up on OnSendingHeaders() .


1 Answers

Adding the following into web.config solution worked across Chrome, IE, Firefox, and Safari:

<?xml version="1.0" encoding="UTF-8"?> <configuration>    <location path="index.html">     <system.webServer>       <httpProtocol>         <customHeaders>           <add name="Cache-Control" value="no-cache" />         </customHeaders>       </httpProtocol>     </system.webServer>   </location>  </configuration> 

This will ensure that the that Cache-Control header is set to no-cache when requesting index.html.

like image 162
Andrew Avatar answered Sep 23 '22 19:09

Andrew