Leverage browser caching with web.config in .net?

2019-04-06 11:25发布

Some of sites are on shared hosting (Windows 2003 Server), so I have no way to access server configuration.

I read everywhere about leverage browser caching, expecially for static files (jpg, css, js, etc.) but... how to do this in my case?

The hosting has .NET installed, could a web.config file help in some way? If yes, how?

2条回答
smile是对你的礼貌
2楼-- · 2019-04-06 12:03

Google PageSpeed Tools will improve rating by providing cacheControlMaxAge in your web.config file but if you want to solve issue completly then use 7 day (represented as days:hours:minutes:seconds) for catch max age

here is code to solve it put this code in to your web.config

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

  </staticContent>
</system.webServer>
查看更多
混吃等死
3楼-- · 2019-04-06 12:04

Here is how I did on my site that is on a shared host. I believe the cacheControlMaxAge is as follows days:hours:minutes:seconds but dont quote me.

<system.webServer>  
    <staticContent>
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="3.00:00:00" />
    </staticContent>
</system.webServer>
查看更多
登录 后发表回答