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?
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