为什么浏览器仍旧发出请求的Cache-Control公众最大年龄? [英] Why does Browser still sends request for cache-control public with max-age?

查看:275
本文介绍了为什么浏览器仍旧发出请求的Cache-Control公众最大年龄?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Amazon S3的对象,并为每个对象,我都设置

I have Amazon S3 objects, and for each object, I have set

Cache-Control: public, max-age=3600000

这是大约41天。

和我有亚马逊的CloudFront的分布设置最小的TTL也与3600000。

And I have Amazon CloudFront Distribution set with Minimum TTL also with 3600000.

这是清除缓存后的第一个请求。

This is the first request after clearing cache.

GET /1.0.8/web-atoms.js HTTP/1.1
Host: d3bhjcyci8s9i2.cloudfront.net
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8

和响应是

HTTP/1.1 200 OK
Content-Type: application/x-javascript
Content-Length: 226802
Connection: keep-alive
Date: Wed, 28 Aug 2013 10:37:38 GMT
Cache-Control: public, max-age=3600000
Last-Modified: Wed, 28 Aug 2013 10:36:42 GMT
ETag: "124752e0d85461a16e76fbdef2e84fb9"
Accept-Ranges: bytes
Server: AmazonS3
Age: 342557
Via: 1.0 6eb330235ca3971f6142a5f789cbc988.cloudfront.net (CloudFront)
X-Cache: Hit from cloudfront
X-Amz-Cf-Id: 92Q2uDA4KizhPk4TludKpwP6Q6uEaKRV0ls9P_TIr11c8GQpTuSfhw==

即使在亚马逊显然发送缓存控制,Chrome浏览器仍使从缓存中读取它第二次请求,而不是。

Even while Amazon clearly sends Cache-Control, Chrome still makes second request instead of reading it from Cache.

GET /1.0.8/web-atoms.js HTTP/1.1
Host: d3bhjcyci8s9i2.cloudfront.net
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
If-None-Match: "124752e0d85461a16e76fbdef2e84fb9"
If-Modified-Since: Wed, 28 Aug 2013 10:36:42 GMT

问: 为什么铬使得第二个请求?

Question: Why does chrome makes second request?

过期 当我把一个明确的到期属性的头这种行为变化。浏览器将不发送后续请求Expires头,但对于缓存控制公开,但它发送。我所有的S3对象,永远不会改变,它们是不可变的,当我们改变的文件,我们把它们与新的URL新的对象。

Expires This behavior changes when I put an explicit Expires attribute in headers. Browser will not send subsequent request for Expires header, but for cache-control public, it does send it. My all S3 objects will never change, they are immutable, when we change file, we put them as new object with new URL.

在页面脚本参考 Chrome浏览器,使后续的请求只是有时,我通过实际输入网址,浏览器做了这个测试。当脚本由HTML页面引用,对一些后续的请求铬负荷缓存中的脚本,但经过再一次的某个时候,曾经在一段时间它发送请求给服务器。这里没有盘大小的问题,浏览器有足够的缓存空间。

In Page Script Reference Chrome makes subsequent requests only sometimes, I did this test by actually typing URL in browser. When script is referenced by HTML page, for few subsequent requests chrome loads cached scripts, but once again after sometime, once in a while it does send request to server. There is no Disk Size issue here, Chrome has sufficient cache space.

问题是,我们得到收费为每一个请求,我想永远缓存S3的对象,而应该从缓存中加载,并且不应该连接到服务器了。

Problem is we get charged for every request, and I want S3 objects to be cached forever, and should be loaded from Cache and should never connect to server back.

推荐答案

如果HTTP响应包含ETag的进入,条件请求将始终进行。 ETag的是一个缓存验证标签。客户端将总是发送的etag到服务器,以查看是否该元件已被修改。

If the HTTP Response contains the etag entry, the conditional request will always be made. ETag is a cache validator tag. The client will always send the etag to the server to see if the element has been modified.

这篇关于为什么浏览器仍旧发出请求的Cache-Control公众最大年龄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆