0
votes

I'm new to HTTP caching and really need some help...

  1. I saw many people set the "Cache-Control" header when sending XHR to server. What is the purpose of doing that? Does request header needs caching too?

  2. I've set this header for a XHR: Cache-Control max-age=30, must-revalidate, but Firefox 3.6.13 seems do not re-validate the file when I refresh(even force refresh) after 30 seconds. No access-log in server either. Is this because I haven't set expire header to the file in Apache?

    From Firebug log:

    Response Headers
    Date Sat, 22 Jan 2011 09:59:21 GMT
    Last-Modified Thu, 20 Jan 2011 09:05:11 GMT
    Etag "3e000000023ca7-20d-49a436e5b3413"

    Request Headers
    Keep-Alive 115
    Connection keep-alive
    Content-Type application/xml
    Cache-Control max-age=30, must-revalidate

    The file have been modified, but Firefox does not even do conditional get. Response Date and Last-Modified not update at all.

2

2 Answers

1
votes

the server needs to set the re-validate directive, not the client.

the source controls if and how the content should be cacehd or not cached, the clients decides whether to honor it or not.

must-revalidate just means that a head request is sent and if the etag differes, the resources is refreshed. this is a very common an dsenseful practice for big files, because the e-tag generally changes once the content changes.

for small files however it may be your desire to not have any request at all, but a shorter time out. then must-revalidate is wrong. the server load and the time it consumes of a head request to a 7kb image is not much less than serving the complete image.

2
votes

Clients can send Cache-Control directives too. See: http://tools.ietf.org/html/draft-ietf-httpbis-p6-cache-12#section-3.2

Unfortunately, browsers won't (yet) honour them when set by XHR, but intervening proxy caches generally will.