Caching only images, no cookies

Per Buer perbu at
Wed Feb 2 10:49:02 CET 2011


On Wed, Feb 2, 2011 at 10:14 AM, David Murphy <david at> wrote:
> Morning Per
> So the default behaviour of Varnish (only extended if I start writing
> my own .vcl) would make a smart choice about what should be cached?
> That sounds good. So provided that I strip the cookies for the image
> file types, then Varnish will spot that these request do not have any
> cookies and will safely cache them, ignoring all other requests (since
> I've not stripped their cookies).


> Something as simple as
> sub vcl_recv {
>   if (req.url ~ "\.(png|gif|jpg)$") {
>        remove req.http.Cookie;
>    }
> }

Right. Provided your backend produces sane cache-control headers. If
there is no information on how long to cache it Varnish will cache for
a default period of 120 seconds. You can override the TTL -

> ...and nothing else in .vcl file?

No. That should be sufficient.

Per Buer, Varnish Software
Phone: +47 21 98 92 61 / Mobile: +47 958 39 117 / Skype: per.buer
Varnish makes websites fly!
Want to learn more about Varnish?

More information about the varnish-misc mailing list