views:

1050

answers:

3
+3  A: 

What are you doing in your browser? I looks like you click the reload button or even something like shift+Reload. Normally, the browser wouldn't send a Cache-Control: max-age=0 header. That means the browser has thrown away the cached image and wants to get it again.

If you just navigate to another page and then back again, the browser should respect your Expires header.

Additionally, you could add a Cache-control: public header to your response. That allows proxies and the browser explicitly to cache the image.

chris166
This sure seems right. The browser (Firefox?) is sending max-age=0, which means it doesn't want any response older than 0s, ie, it wants to hit the origin web server. This is the definition of "refresh". Navigate away from your page, then paste in the URL again and see what happens.
Jim Ferrans
Indeed, I was doing a page reload, and I was expecting the browser to reload the html but not all the cached resources as well. I thought you had to do shift-click (or control-click? can't remember) to force the browser to invalidate cache on all the resources. I guess my understanding is incorrect?
I'm not sure about this either. I think browsers behave differently on F5/Reload button with/without Shift.
chris166
A: 

The CGI script looks like it has a timestamp parameter...this isn't changing, is it? The browser should be treating each unique URL as a different object in the cache, so if that is updating with every request, it won't match with the cached image.

Additionally, the Expires field is not exactly in RFC 1123 format, because you need two digits for the date. This may or may not be an issue, but it's something to check. The browser is including Cache-Control: max-age=0, which indicates that it believes its cache to be potentially out of date.

Once the server gets this validation request, it can return 304 (Not Modified), or 200 (OK), as it is doing currently.

Dave Bauman
No, the timestamp isn't changing. And thanks for the tip on the Expires date format, I'll double check.
+1  A: 

The browser ignores the Expires header if you refresh the page. It always checks whether the cache entry is still valid by contacting the web server. Ideally, it will use the If-Modified-Since request header so that the server can return '304 Not modified' if the cache entry is still valid.

You're not setting the Last-Modified header, so the browser has to perform an unconditional GET of the content to ensure that it is up to date.

Some rules of thumb for setting Expires and Last-Modified are described in this blog post:

http://blog.httpwatch.com/2007/12/10/two-simple-rules-for-http-caching/

HttpWatchSupport