Drupal caching prevents cookie read On one of my production sites I wrote a jQuery stylesheet switcher. It drops a cookie when a selection is made and uses php to select the corresponding stylesheet on pageload which overrides styles. All is great until I enable performance caching mode, whereby the cookie is ignored on each pageload. Obviously this isn't the desired effect and I can see why this is occuring: being that the pages are cached and no longer truly dynamic with respect to loading what's seen as a 'dynamically' changing stylesheet. You can change the stylesheet however upon returning to a page the initial style is applied. Just for reference I have coded the php into each page template (page-front.tpl.php and page.tpl.php) and the javascript is located in my scripts.js. The php is basically just a couple of if else statements.

Due to a large volume of traffic I have to enable caching on the site, however ideally would like to retain this style-switcher functionality. Is there a method of making an exception to the caching rule for this or will I have to disable the switcher? Would packing it into a module help?

Thanks in advance :)
I think you have have a hard time doing this with caching, since you want to create two versions of the same page.

I haven't tried this, but it should be possible to let your style.css not be an actual css file but a drupal callback that returns the styles based on the cookie. You would need to include the "stylesheet" as you would do styles for IE. You wouldn't be able to cache this, but if you really need to performance, you could do it in a php file and skip the drupal bootstrap.

An alternative option would be to let the js itself execute the styles, based on the cookie.

None of these options are ideal, but they should work.