Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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 ( and (, 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


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.