How can I set the expiration date of .js and * .css by age? <clientCache> in web.config doesn't work

What I started with this line of thought was when I was playing with PageSpeed ​​Insights and saw this message:

Google PageSpeed ​​says I need to leverage browser cachine

I have looked through the available forum posts and tried this:

<system.webServer>
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
    </staticContent>
  </system.webServer>

      

Looks simple, but when I checked on both my local server and my remote server, I didn't see any evidence that the cache setting was stuck with Chrome developer tools.

The Chrome Developer tool showed no evidence that the web.config code worked

After some more research, I saw that the best way to do this is from within IIS. However, when I spoke to GoDaddy tech support, they said that IIS is blocked for people like me because IIS changes affect everyone. Therefore the IIS option is not suitable for me.

However, if this was only a server matter, then can't I see how the web.config approach works on the local Visual Studio server? It is clear that I am missing something.

Am I doing this completely wrong or is it a matter of adding an extra line?

I'm starting to think that since web.config doesn't do the job and GoDaddy won't modify IIS, could something in Global.asax do the job? [And no, I can't say my client is changing servers.]

+3


source to share


1 answer


Sometimes mime types can be a bit of a pain when dealing with IIS caching. The code below gives you a basic example of how to make sure your mappings are correct. You don't need to do this for every mime type, just a few ...

<staticContent>
  <remove fileExtension=".js" />
  <mimeMap fileExtension=".js" mimeType="text/javascript; charset=UTF-8" />
  <!-- Caching-->
  <clientCache cacheControlMode="UseExpires"
               httpExpires="Tue, 22 Aug 2016 03:14:07 GMT" />
</staticContent>

      



Does the above code match your JavaScript files?

Also, have you tried recycling your application pool? Sometimes the server might have to rework before changes are made.

+2


source







All Articles