2

I am using apache tomcat server and have a web application rendering several js,css and image files. I want to make sure that these files are cached by the browser so that they are not requested each time. However, I noticed that some files are getting cached while others are not. I found out that the response header from the app has Expires : "Dec 31 1969 at 7:00 PM". After going through this I removed the tomcat security-constraint from the web.xml which removed the header successfully. I also configured the Expires header in my app to 1 week from present. That too didn't make sure that the pages are cached.

Following this I configured the Cache-Control header to public with max-age set to 1 week. None of these changes are helping me. Moreover, the pages getting cached and not getting cached have the same headers as below:

HTTP/1.1 200 OK
Cache-Control: max-age=604800, public
ETag: 240983
Last-Modified: Fri, 09 Sep 2016 18:49:42 GMT
Date: Wed, 01 Feb 2017 07:34:25 GMT
via: HTTP/1.1 ab-d-klt-tom1
Expires: Wed, 08 Feb 2017 07:35:29 GMT
Content-Type: application/x-javascript
Transfer-Encoding: chunked
Content-Encoding: gzip
Vary: Accept-Encoding
X-FRAME-OPTIONS: SAMEORIGIN
X-Powered-By: Servlet/3.0
X-UA-Compatible: IE=edge
Server: Apache 

Apart from this I have also tried the ExpiresFilter as described here without any luck.

EDIT : My application when deployed in a windows environment with Tomcat and no SSL is successfully caching all the files in the browser.

However, when the app is deployed in a Linux environment with Tomcat and SSL is not caching files. Is SSL causing this?

Community
  • 1
  • 1
adarsh hegde
  • 1,353
  • 2
  • 21
  • 43
  • Can you show us HTTP headers of a request of a resource that isn't cached by a browser? – Leonid Vasilev Feb 01 '17 at 11:13
  • @LeonidVasilyev I have edited my post above. Could SSL be causing this issue? – adarsh hegde Feb 01 '17 at 11:17
  • The request headers are as follows: GET /html/en/default/***.css HTTP/1.1 Host: 10.62.137.70 Connection: keep-alive User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36 Accept: text/css,*/*;q=0.1 Referer: *** Accept-Encoding: gzip, deflate, sdch, br Accept-Language: en-US,en;q=0.8 Cookie: _ga=GA1.1.794081272.1485321205; _gat=1; JSESSIONID=*** – adarsh hegde Feb 01 '17 at 11:21
  • Does Chrome display any errors regarding your SSL certificate? – Leonid Vasilev Feb 01 '17 at 12:28
  • Yes the "https" and padlock have a cross in chrome and says "Your connection to this site is not secure". – adarsh hegde Feb 01 '17 at 12:44

1 Answers1

3

You need to get rid of SSL certificate error. Chrome does not cache resources with such errors.

For more information check Chromium issues below:

Leonid Vasilev
  • 11,910
  • 4
  • 36
  • 50