Cookies - set on non-cached pages, read on all pages

David Murphy David at firechaser.com
Tue Apr 20 13:02:01 CEST 2010


Hello

We use a javascript cookie to display the user's first name in the header of our site. Our site uses Varnish to cache all pages except a login page, where the cookie is set.

What we need to be able to do is set the cookie once (name='David') on the login page so that we can display 'Hello David' on all other pages.

For a given cached page, if the user's browser already has a cookie saved, then we display its value ('Hello David'). If no cookie is found then we display 'Login'.

We only want a single instance of each cached page in Varnish (rather than a unique cached page per user) so that all users - whether they have the cookie or not - will be given this same page from the cache. 

So, if we set the cookie on the dynamic login page, how would we go about making sure that for all the other pages cached by Varnish, the cookie value (already stored in browser) is available to be read by JS code that is part of the cached XHTML markup.

Thanks for any help.

Best, David



More information about the varnish-misc mailing list