Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser (Chrome) does not cache assets from CloudFront [closed]

Scenario:

I setup a Cloudfront distribuition from custom origin (my server) to progressive stream a list of mp4 video files.

These files are looped and played thru the Chrome native HTML5 video api. Every time the video ends Chrome make another request to the file.

When playing the file from my server, Chrome returns

Status Code:206 Partial Content (from cache)

on each request, while when playing the same file from CloudFront, Chrome never caches the file and keeps downloading it at each request!

These are the response headers from Amazon CloudFront in Chrome:

HTTP/1.0 206 Partial Content
Date: Mon, 19 Mar 2012 19:47:44 GMT
Server: Apache
Last-Modified: Mon, 19 Mar 2012 12:35:37 GMT
ETag: "a78e87ba-335d8e-4bb97cb9f887f"
Accept-Ranges: bytes
Content-Type: video/mp4
Content-Range: bytes 4228-3366285/3366286
Content-Length: 3362058
Age: 3819
X-Cache: Hit from cloudfront
X-Amz-Cf-Id: xxxxxx
Via: 1.0 xxxxxx.cloudfront.net (CloudFront)
Connection: keep-alive 

Response Headers in Chrome of the same file from my server (origin):

HTTP/1.1 206 Partial Content
Date: Mon, 19 Mar 2012 20:50:40 GMT
Server: Apache
Last-Modified: Mon, 19 Mar 2012 12:35:37 GMT
ETag: "a78e87ba-335d8e-4bb97cb9f887f"
Accept-Ranges: bytes
Content-Length: 3366286
Content-Range: bytes 0-3366285/3366286
Keep-Alive: timeout=2, max=256
Connection: Keep-Alive
Content-Type: video/mp4

Am I missing something?

Maybe the reason is in the lack of the Keep-Alive header from CloudFront response? or maybe in the different HTTP protocol version (1.0 vs 1.1)?

like image 890
null Avatar asked Mar 19 '12 21:03

null


1 Answers

From your CloudFront response:

HTTP/1.0 206 Partial Content

HTTP/1.0 doesn't contain a 206 response code (that was added in HTTP/1.1) so chrome's cache layer refuses to reuse the response. More chrome-specific details in http://crbug.com/128116 but the short answer is that CloudFront should serve 206 responses as HTTP/1.1, not /1.0.

like image 188
Ami Avatar answered Sep 28 '22 08:09

Ami