views:

26

answers:

1

I'd like an HTTP response to expire 24 hours from now (meaning the browser won't make any requests for that URL until tomorrow). But, if the request is re-issued tomorrow after expiration, I want to make sure the browser will send the right request headers so that the server will send a 304 instead of forcing the client to re-download the whole response body if it hasn't changed on the server. And I'd like that 304 to also expire 24 hours later.

First, is this sccenario possible? Or do I have to choose between Expiration-style caching and 304-style caching, but not both? If it is possible, what are the right response headers (both for the initial response and for the subsequent 304s) which will make it happen?

If as often happens, the answer varies based on browser type/version, then which headers work for which browsers-- and which browsers won't be able to do what I want at all? I'm only interested in the most common browsers in use today (e.g. IE6+, FF3+, Chrome latest, Safari latest)?

Apologies if this answer has already been asked on SO-- I searched for a while and came up blank.

CLARIFICATION: I'm asking this question because I'm putting together an automated test suite to verify, regardless of server platform, that a web app is generating the correct HTTP headers to generate the client-caching behavior we want all our web apps to have. So I'm not interested (at least for now) in how to configure Apache/IIS/PHP/Rails/Django/JSP/ASP.NET/etc. to generate the right headers. I simply want to know, at the HTTP layer only, what the right headers are.

+1  A: 

I recommend using the ETag header.

Avi Flax
ETag alone isn't enough, as clients will still make a new HTTP request each time to check if the ETag is still current. At least one additional header is needed to control content expiration to prevent making any requests for 24 hours before checking back for a new ETag.
Justin Grant
Very helpful, thanks Justin! So I guess you'd need to use the `Expires` header along with `ETag`, right?
Avi Flax