浏览器未发送If-None-Match标头

时间:2019-04-04 15:25:25

标签: web-applications browser-cache servlet-filters cache-control etag

由于每次登录过程中都会下载大量文件,因此我试图修复Web应用程序的性能。为此,我希望启用条件浏览器缓存,即,如果ETag更改,则从服务器提供新副本,否则使用浏览器缓存。

通过Java过滤器从服务器发送响应头:

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

在浏览器下一次调用时,发送的请求标头为:

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=*********

浏览器没有发送If-None-Match标头,因此用于验证ETag并发送回304响应代码的服务器端代码失败,并且服务器总是将新副本发送给客户端。

我尝试了其他Cache-Control标头,例如:

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

但无济于事。 有人可以帮忙。每当ETag更改时,对于Web应用程序来说,提供新鲜的内容也很重要。

1 个答案:

答案 0 :(得分:0)

您的ETag无效,因为它缺少specification所需的双引号。试试:

ETag: "040419095614"
相关问题