I am setting Expires filter in web.xml of Tomcat. The header comes correctly in response but still IE is not caching. It is always making the fresh request to Tomcat.
<filter>
<filter-name>ExpiresFilter</filter-name>
<filter-class>org.apache.catalina.filters.ExpiresFilter</filter-class>
<init-param>
<param-name>ExpiresByType image/png</param-name>
<param-value>access plus 2 hours</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>ExpiresFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
Below are the headers from respone
Cache-Control: max-age=7199
Expires: Mon, 14 Nov 2016 16:08:22 GMT
Content-Type: image/png
Transfer-Encoding: chunked
Date: Mon, 14 Nov 2016 14:08:22 GMT
Does anyone know, what am I missing here?
If specified, HTTP request cache-control headers are ignored for caching decisions. This option available under Web Sites > Traffic management > Caching > Edit the service and set the value of 'Ignore Request Headers' to Yes.
When you're in Google Chrome, click on View, then select Developer, then Developer Tools. Alternatively, you can right click on a page in Chrome, then click Inspect. Click on the Network tab, then check the box to Disable cache. You can then close out of Developer Tools.
Cache-control is an HTTP header used to specify browser caching policies in both client requests and server responses. Policies include how a resource is cached, where it's cached and its maximum age before expiring (i.e., time to live).
If you want to enable Cache-Control for all files, add Header set line outside the filesMatch block. As you can see, we set the Cache-Control header's max-age to 3600 seconds and to public for the listed files.
There is Microsoft's own documentation on cache-control.
Short answer: you have to use Pragma: no-cache
, Cache-Control: no-cache
and Expires
all together.
Update 2019-01-24
The above instructions are for disabling caching, while the answer to being able to force caching can be found in this fine SO answer: Make IE to cache resources but always revalidate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With