Question

I'm using AWS SDK for .NET to upload several images. Before making the PutObjectRequest, I set the max-age and expires headers for far future intervals and dates, respectively.

This is the initial image request:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Host:assets.mywebsite.com.s3-us-west-1.amazonaws.com
If-Modified-Since:Sun, 19 Feb 2012 18:36:48 GMT
If-None-Match:"f19920f9367b698451d6c964d3ae714a"
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11

Here is the S3 response. It sends back the correct caching headers:

Accept-Ranges:bytes
Cache-Control:public, max-age=31536000
Content-Length:9180
Content-Type:image/jpeg
Date:Sun, 19 Feb 2012 19:16:18 GMT
ETag:"f19920f9367b698451d6c964d3ae714a"
Expires:Sat, 19 Feb 2022 18:36:48 GMT
Last-Modified:Sun, 19 Feb 2012 18:36:48 GMT
Server:AmazonS3

However, every subsequent request still results in a 304 (not a 200 from cache):

Status Code:304 Not Modified

Note, I'm not hitting F5.

I've read that when you mix ETags and Expires/Cache-Control, ETags will generally be used for each request and ignore caching altogether. I've also read that there is no way to disable ETags in S3.

I'm simply trying to increase speed and decrease costs. Before I give up I figured I'd ask the SO community.

Any Ideas on how to prevent the 304's?

UPDATE:

It would appear browsers are becoming more and more sophisticated as far as caching goes. As marcind points out, it's a client browser issue. After testing in other browsers and different scenarios (ie, loading the image directly in chrome (requesting the image url) as opposed to simply viewing the image in the presence of a web page has different effects)

Was it helpful?

Solution

What are the headers going out with subsequent requests? Looks like your client might be sending an If-Modified-Since or something similar.

update: since your client is sending If-Modified-Since Amazon is doing the right thing. This looks like a problem with your client.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top