Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

It seems that a dozen pages exist that tell you how to set your "expires" headers for files, but none that are actually correct.

Right now, my VCL is:

if (req.url ~ "^/media/") {
    set beresp.ttl = 3600s;
    set beresp.http.expires = beresp.ttl;
    set beresp.http.age = "0";
    unset beresp.http.set-cookie;
}

and the browser keeps re-requesting files under /media/ for every request. Can someone share a VCL snippet that will actually tell the browser to cache the object for as long as Varnish does, and not re-request it each time?

My response headers are:

Server Apache/2.2.14 (Ubuntu)
Last-Modified Sun, 15 Aug 2010 22:26:50 GMT
Etag "141d8-184e-48de4364e3e80"
Vary Accept-Encoding
Content-Encoding gzip
Content-Type text/css
Expires 3600.000
Content-Length 1802
Date Mon, 16 Aug 2010 12:16:48 GMT
X-Varnish 808143209 808142052
Age 2184
Via 1.1 varnish
Connection keep-alive

I'm not sure which header is making the browser request the CSS each time, but it does. Help?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

How about setting the cache-control header as well?

set beresp.http.cache-control = "max-age = 3600";

If your browser doesn't see that header, it may be inclined to request the object every time. Hope this helps.

share|improve this answer
    
That doesn't appear to work, the browser still requests it :/ –  Stavros Korokithakis Aug 16 '10 at 12:46
    
Hmm.. taking a look at this example (pastebin.com/7KpZrAG0) and (permalink.gmane.org/gmane.comp.web.varnish.misc/3563), it appears that they UNSET the expires header and only set the cache-control header. Give that a shot? –  vmfarms Aug 16 '10 at 13:08
    
That worked, thank you! Bye bye, expires header! –  Stavros Korokithakis Aug 16 '10 at 13:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.