How to make images can be cached by client browsers via varnish?

时间:2016-08-31 12:29:19

标签: caching varnish cache-control

body:

  • I add the Cache-Control http header when vcl_deliver, like: enter image description here

  • I found the chrome broswer's debug console: enter image description here

  • I think the response code should be 304, not 304 Not Modified,I hope the browser caches the image(don't request the varnish) but it doesn't work.

Could you suggest me?

Thanks & Regards.

1 个答案:

答案 0 :(得分:0)

您需要在将来的某个时间添加Expires响应标头集。 在当前状态缓存工作中,允许浏览器保存缓存副本一年 但由于没有过期,它必须验证服务器端的内容,可能使用条件请求标头,例如If-None-Match(如果您在响应标头中使用E-Tag)或If-Modified-Since(如果使用正在使用Last-Modified)。

您可以使用以下vcl代码段(从https://www.varnish-cache.org/trac/wiki/VCLExampleSetExpires借用)添加Expires标头:

set beresp.http.Expires = "" + (now + beresp.ttl);

但是,我在请求标头中看不到If-Modified-Since。这很奇怪,因为它应该允许清漆以304响应。

PS> 304304 Not Modified并不重要,现在好了。

相关问题