Caching only images, no cookies

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

Hi David,

On Wed, Feb 2, 2011 at 9:55 AM, David Murphy <david at> wrote:
> Hello
> I would like to use Varnish to only cache images and to strictly never
> cache any cookies. Previous attempts at writing the .vcl file led to
> situations where if an image was missing from the server, the
> underlying CMS would try to generate a new images (using Imagecache)
> and this led to session swapping because cookies were cached and the
> passed onto other users.

Right. Sound bad.

> So, I'm looking to have a very simply, reliable script that only cares
> about images and cannot in any circumstances cache cookies.
> Would something like this do the trick?
> sub vcl_recv {
>  if (req.url ~ "\.(png|gif|jpg)$") {
>    lookup;
>  }
> }

No. Just drop the relevant cookie in vcl_recv. If you strip away the
cookies the image will be cached by the built in logic. Easy and safe.

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