0

For browser caching, I want to set expiration time for only one of my .js file in web.config not the whole js folder. For that I tried using the below configuration with the help of How to configure static content cache per folder and extension in IIS7? but it doesn't work:

    <configuration>
     <location path="compiled.js">
       <system.webServer>
        <staticContent>
         <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
        </staticContent>
       </system.webServer>
     </location>
  </configuration>

Then I tried to change the path in "location" attribute as shown below but this also doesn't work for me:

<configuration>
   <location path="~/js/compiled.js">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
      </staticContent>
    </system.webServer>
    </location>
  </configuration>

Can someone help me how do I set cache expiration time for only one .js file instead of whole folder via web.config?

Community
  • 1
  • 1
Babita
  • 69
  • 7

1 Answers1

0

For a single file we can set caching expiration time in web.config file as shown below:

    <configuration>
    <location path="js/compiled.js">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
      </staticContent>
    </system.webServer>
  </location>
    </configuration>

Also, we can specify the cache settings for different files/folders by using different <location> sections.

Babita
  • 69
  • 7