对于两个后续请求,浏览器会给予以下两个标题中的哪一个更多权重:其中一个更改:ETag或Last-Modified?
我在App引擎上有一个servlet来提供图像.
servlet正确设置HTTP标头值以指示应缓存图像.但App Engine会覆盖这些标题,导致图像不被缓存.
请注意,之前相同的代码工作,但现在它不起作用.
App Engine的文档指出,如果Cache-Control,Expires和Vary报头由servlet设置,他们将留不变:
https://developers.google.com/appengine/docs/java/runtime#Responses
这是我的示例代码:
response.setContentType( "image/jpeg" );
//response.setDateHeader( "Expires", new Date().getTime() + 60L*24*60*60*1000 ); // 60 days cache time
//response.addHeader( "Cache-Control", "public, max-age=5184000" ); // 5_184_000 sec = 60 days cache time
response.addHeader( "Cache-Control", "public, max-age=90000" ); // 90_000 sec = 25 hours cache time
response.getOutputStream().write( data ); // Data is a byte array containing the JPEG image data
Run Code Online (Sandbox Code Playgroud)
(我已经尝试过把所有内容都注释掉了.)
检查HTTP请求 - 响应,响应包含以下标头:
HTTP/1.1 200 OK
status: 200 OK
version: …Run Code Online (Sandbox Code Playgroud)