Implementing static files cache in asp.net mvc
asp.net, asp.net-mvc, asp.net-mvc-4, caching
Solution
This is correct, and you should be fine.
Some might say you should add `Expires`, too, for clients which do not understand HTTP/1.1, but as already argued in the first linked article, that shouldn't be a real concern, even less now, 7 years later.
Problem
I am trying to implement static files cache in the ASP.net mvc application. What i did: I've added into `Content` folder a `web.config` file with the following content: ``` <?xml version="1.0"?> <configuration> <system.webServer> <staticContent> <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="300.0:00:00" /> </staticContent> </system.webServer> </configuration> ``` In the website `web.config` file, i commented out some lines of code: ``` <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <handlers> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> <!-- Commented them out <add verb="GET" path="*.js" name="Static for js" type="System.Web.StaticFileHandler" /> <add verb="GET" path="*.css" name="Static for css" type="System.Web.StaticFileHandler" /> <add verb="GET" path="*.png" name="Static for png" type="System.Web.StaticFileHandler" /> <add verb="GET" path="*.jpg" name="Static for jpg" type="System.Web.StaticFileHandler" /> --> </handlers> ``` Now, publishing the website and inspecting the resources, i get the folowing response: I see is missing the `Expire` header ?! (shouldn't it be there in order for cache to work) Does the response headers tell the browser to cache the resource for the next 25920000 seconds? I am doing things correctly in order to cache the static files?