Set caching on CSS files on IIS7 is not working - iis-7

I am trying to implement the advice from Google's Pagespeed concerning browser caching(Set Expirer or Cache-control headers on static content).
After reading many posts here (like IIS7 Cache-Control ) and on other website I just can't seem to figure out why Pagespeed is for example still disapproving my CSS files.
For example: http://test.grotefeesten.nl/clientdata/71/js/jssor.config.js. This file has an expiration time of 1 day according to local PageSpeed but not according to the online PageSpeed test.
My web.config:
<caching>
<profiles>
<add extension=".css" policy="CacheUntilChange"
kernelCachePolicy="CacheUntilChange" location="Any" />
</profiles>
</caching>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="public" />
</customHeaders>
</httpProtocol>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlCustom="max-age"
cacheControlMaxAge="1.00:00:00" />
</staticContent>
Does anybody see what I am missing here to set the Expires header properly?

I had been struggling with this myself. However, I found a solution:
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="max-age=2592000" />
</customHeaders>
</httpProtocol>
This was all it took. The value in the code above, "max-age=2592000", is 1 month.

Related

Removing Server tag in Header of IIS10

I am asking this question here because every other trick in the book from various sites including microsofts has failed to fix this for me.
I have added
<security>
<requestFiltering removeServerHeader="true" />
</security>
in <system.webserver>
Then i also added
<system.web>
<httpRuntime enableVersionHeader="false"/>
</system.web>
also added
<httpProtocol>
<customHeaders>
<clear />
</customHeaders>
</httpProtocol>
However none of this seems to remove the "Server" header from the response.
Any idea as to what else i can try other than URlRewrite or outboundrule??

I have an error when loading wordpress site

I have this site but the css files do not seem to load correctly :http://185.58.193.198:12500/HelpDesk/
Can some tell me what changes i should make. I have used wamp for the database and IIS for hosting
There many reasons for 403 error, you can try to add below code in your web.config file:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>
</system.webServer>
and you can also try enabled anonymous authentication in iis authentication.

Cannot get ASP.NET/IIS to serve .js files with custom cache-control settings

In my ASP.NET MVC 5 app, I have used the clientCache web.config attribute to customize the caching behavior for static files.
<system.webServer>
<staticContent>
<clientCache cacheControlCustom="private,max-age-300" setEtag="true" />
</staticContent>
</system.webServer>
This is working fine for .css and image files, but I'm noticing in my browser's dev tools that .js files are not getting the custom cache-control and etag headers that the other file types are getting.
In addition, I've tried adding a custom handler, but it hasn't had any effect from what I can tell.
<handlers>
<add name="StaticHandler_js" verb="*" path="*.js" type="System.Web.StaticFileHandler" />
</handlers>
Any ideas on how I can get ASP.NET/IIS to treat .js files the same way as other static files?
I was able to get around this by adding path-specific configuration to clear out all handlers and add only the static file defaults to those paths. This is an imperfect solution because it's based on the file path, not the file type, but because all of my JavaScript files are in this singular folder, it does the job.
<location path="Scripts">
<system.webServer>
<handlers>
<clear />
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read"/>
</handlers>
</system.webServer>
</location>
If anyone has a better solution that doesn't rely on file path, I'll gladly accept that as the solution.
<system.webServer>
<staticContent>
<clear/>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:01:00" />
<mimeMap fileExtension=".jpg" mimeType="image/jpg"/>
<mimeMap fileExtension=".png" mimeType="image/jpg"/>
<mimeMap fileExtension=".css" mimeType="text/css"/>
<mimeMap fileExtension=".js" mimeType="text/javascript"/>
</staticContent>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>

Disabling Output caching through web.config

I am trying to neatly disable output caching for WCF application. enableOutputCache attribute does not work for some reason, can someone explain the reason, or suggest a work around.
<system.web>
<caching>
<outputCache enableOutputCache="false" enableFragmentCache="false"></outputCache>
<outputCacheSettings>
<outputCacheProfiles>
</outputCacheProfiles>
</outputCacheSettings>
</caching>
</system.web>
Thanks
I know this is an old question but I'd like to give my two cents. I actually needed to disable caching of webapi services that are called by a SPA, and on some versions of IE they where cached by default unless the cache-control:no-cache and similar headers where present. What I did to enable browser caching of static resources and disable it for all the services was add the headers depending on the location using the web-config.
i.e.
<location path="api">
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="no-cache" />
<add name="Expires" value="-1" />
<add name="Pragma" value="no-cache" />
</customHeaders>
</httpProtocol>
</system.webServer>

Overwrite web.config setting

Environment: IIS 7, .Net 4.0
In web.config of our application, it has this section:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="cache-control" value="no-cache" />
</customHeaders>
</httpProtocol>
</system.webServer>
Most of our application requires no-cache, but there is only one page that requires cache-control to be Private. Is a way to do it?
Appreciated for any input
You cannot apply or override settings from web.config to a particular page, however you can do this for all pages inside a folder, by following settings.
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="cache-control" />
<add name="cache-control" value="no-cache" />
</customHeaders>
</httpProtocol>
</system.webServer>
However, you can override the cache-control settings in Page_Load event of a particular page.
Response.CacheControl = "Private";
You can also change response caching for a page by setting the location attribute of #outputcache directive.
<%# OutputCache Location="Server" %>

Resources