In a previous article I discussed how to optimize your ASP application via HTTP Compression. In this article I will demonstrate how to save bandwidth and make your page load faster by adding expiry header to static files in ASP.net.
Usually, you can cache static files such as images, stylesheets and script files. By making some changes in the web.config file, we can set the browser to cache all these files.
Add this code to your web.config which will cache all static files of your application in the browser for 2 years:
<system.webServer><staticContent> <clientCache cacheControlCustom="UseMaxAge" cacheControlMaxAge="730.00:00:00"/> </staticContent> </system.webServer>
This setting is very useful if you don’t make style changes in your ASP application. Nevertheless, if a user makes a hard refresh (Control + F5) on his web browser, the cache will be updated. Most users don’t do hard refreshes, and this code will make your application load faster.
This concludes Adding expiry header to static files in ASP.net