Shubham Jain
Shubham Jain

Reputation: 21

If-None-Match Header not being sent by browsers

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.

Upvotes: 1

Views: 1944

Answers (2)

Mark Arrow
Mark Arrow

Reputation: 88

I know it has been a long time since this had been active, but I recently had a similar issue.

In my case, the If-None-Match header was properly sent by the frontend, but when we look at the logging, the If-None-Match header never reached our nginx proxy for some of our users. Turns out some companies filter these headers out and therefore no If-None-Match headers will reach the server.

So if someone ever comes across this issue again, this could be a potential cause.

Upvotes: 0

Kevin Christopher Henry
Kevin Christopher Henry

Reputation: 48992

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

ETag: "040419095614"

Upvotes: 2

Related Questions