使用https协议的Http缓存

时间:2013-11-20 10:51:18

标签: http caching https http-headers

我为我的rails应用程序设置了缓存。我使用ETag和Last-Modified标头的条件缓存用于少数页面,而浏览器缓存使用Cache-Control标头用于少数其他页面。它工作正常。

但是,在我们为服务器设置ssl之后,浏览器不希望从缓存中获取页面。我看到http和https协议的标题相同,但对于网络面板中Chrome Developer工具中的http协议,我看到缓存页面的状态代码200(来自缓存),但这些页面使用https协议可以200 OK。以下是请求标头列表:

Accept:text/html, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,ru;q=0.6
Connection:keep-alive
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie: ...
Referer: ...
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1712.3 Safari/537.36
X-PJAX:true
X-PJAX-Container:#pjax-container
X-Requested-With:XMLHttpRequest
Query String Parametersview sourceview URL encoded

响应标题:

Cache-Control:max-age=600, public
Connection:keep-alive
Content-Encoding:gzip
Content-Type:text/html; charset=utf-8
Date:Wed, 20 Nov 2013 10:38:07 GMT
Last-Modified:Wed, 20 Nov 2013 08:41:45 GMT
Server:nginx/1.1.19
Set-Cookie: ...
Status:200 OK
Transfer-Encoding:chunked
X-Content-Type-Options:nosniff
X-Frame-Options:SAMEORIGIN
X-Request-Id:71c60772-bc9f-4080-98ad-0c75c589043a
X-Runtime:0.047251
X-UA-Compatible:chrome=1
X-XSS-Protection:1; mode=block

对于条件缓存,我有类似的问题。服务器设置Last-Modified标头,但对于下一个请求浏览器不发送'If-Modified-Since'标头,因为它条件缓存不起作用。它适用于http协议。以下是请求标头列表:

Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,ru;q=0.6
Connection:keep-alive
Cookie: ...
Referer: ...
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1712.3 Safari/537.36
X-CSRF-Token: ...

响应标题:

Cache-Control:max-age=0, private, must-revalidate
Connection:keep-alive
Content-Encoding:gzip
Content-Type:application/json; charset=utf-8
Date:Wed, 20 Nov 2013 10:41:33 GMT
Last-Modified:Wed, 20 Nov 2013 10:20:44 GMT
Server:nginx/1.1.19
Set-Cookie: ...
Status:200 OK
Transfer-Encoding:chunked
X-Content-Type-Options:nosniff
X-Frame-Options:SAMEORIGIN
X-Request-Id:35054727-1b1a-497d-a830-6499ed9cad7a
X-Runtime:0.012432
X-UA-Compatible:chrome=1
X-XSS-Protection:1; mode=block

浏览器从此服务器缓存css和js文件,但不渲染页面。为什么浏览器不为https协议缓存页面?如何让浏览器缓存这些页面?

0 个答案:

没有答案