1
votes

I am trying to fix the performance of a web-application due to heavy file downloads during every login. For that, I wish to enable conditional browser caching, i.e, if the ETag changes, serve the new copy from server, else use browser cache.

Response Headers being sent from server via java filter:

HTTP/1.1 200 OK
Cache-Control: max-age=25200, s-maxage=25200, private, must-revalidate
Date: Thu, 04 Apr 2019 15:12:28 GMT
Pragma: no-cache
Accept-Ranges: bytes
Content-Length: 875914
Content-Type: text/javascript
Last-Modified: Thu, 04 Apr 2019 12:05:21 GMT
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=31536000; includeSubDomains
ETag: 040419095614
Cookie: JSESSIONID=*******; secure; HttpOnly
X-Frame-Options: SAMEORIGIN

On next call by browser, the request headers sent are:

GET ***.js HTTP/1.1
Host: *****
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
Accept: */*
Referer: *****
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cookie: JSESSIONID=*********

There is no If-None-Match header being sent by the browser and therefore the server side code for validating the ETag and sending back 304 response code fails and always a fresh copy is sent by the server to the client.

I have tried other Cache-Control header like:

Cache-Control: no-cache, must-revalidate, max-age=0  

but to no avail. Could someone please help. Also it is very important for the web-application to serve fresh content whenever the ETag changes.

1

1 Answers

0
votes

Your ETag is invalid because it's missing the double-quotes required by the specification. Try:

ETag: "040419095614"