3

I have a website hosted in IIS 10

The .js and .css files are versioned using this pattern ?v=a.b.c (where a.b.c is changed with a new number every time is required) in order to invalidate the cache browser.

This is how the site starts :

  • user enters www.sitename.com (or "localhost" in my case)
  • the index.html file is loaded . This files loads a main.js?v=a.b.c file that loads/configures "require.js" . Every other file from this point forward is handled by require (also management of the versioning for the html/css/js)

The problem that I am facing is the following : How to invalidate the cache browser for index.html ?

I tried to send a no-cache header for the index.html with the following web.config file in IIS that works if I write localhost/index.html in the browser URL...but it does not work if I write only localhost (in this case the old index.html from the cache is loaded)

<configuration>
 <system.web>
   <urlMappings enabled="true">
     <add url="~/" mappedUrl="~/index.html" />
   </urlMappings>
 </system.web>
 <location path="index.html">
    <system.webServer>
        <staticContent>
            <clientCache cacheControlMode="DisableCache" />
        </staticContent>
    </system.webServer>
 </location>
</configuration>

Can I receive some help ?

Lucian
  • 344
  • 1
  • 6
  • 19
  • Is your issue solved? If your issue is solved then I request you to mark the helpful suggestion as an answer. This will help other people who face the same issue. If your issue still exists then try to refer the solution given by the community members. If then also you have any further questions then let us know about it. We will try to provide further suggestions to solve the issue. Thanks for your understanding. – Jalpa Panchal Sep 25 '20 at 02:35

1 Answers1

1

you can set the no-cache header by using iis URL rewrite rule:

<system.webServer>
<rewrite>
 
<outboundRules>

  <rule name="RewriteCache-Control" preCondition="old url with 301" stopProcessing="true">
    <match serverVariable="RESPONSE_Cache-Control" pattern="(.*)" />
    <conditions>
    </conditions>
    <action type="Rewrite" value="no-cache" />
  </rule>
  <preConditions>
    <preCondition name="old url with 301">
                        <add input="{URL}" pattern="index.html|^$" />
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
    </preCondition>&gt;
  </preConditions>
</outboundRules>

 </rewrite>
        <tracing>
            <traceFailedRequests>
                <add path="*">
                    <traceAreas>
                        <add provider="WWW Server" areas="Rewrite" verbosity="Verbose" />
                    </traceAreas>
                    <failureDefinitions statusCodes="100-900" />
                </add>
            </traceFailedRequests>
        </tracing>
</system.webServer>

another way:

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

enter image description here

Jalpa Panchal
  • 8,251
  • 1
  • 11
  • 26