I use theme key to switch the theme for mobile devices. When Drupal Cacheing is enabled, Theme Key fails to switch the theme.

Comments

mkalkbrenner’s picture

Status: Active » Closed (works as designed)

That's not a bug. That's how drupal core page caching works.

Everything is documented in the ThemeKey property explainations within the module itself. And you get a warning when you save such rules and page caching is enabled.

If you search through the all the issues you'll find different approaches how to combine mobile themes and page caching.

info@cgfix.com’s picture

Oh my bad, I don't know what gave me the wrong idea?

Oh, I guess it was this sentence at the TOP OF THE MODULE PAGE!

"And unlike other theme switching modules, ThemeKey should play well with internal and external page caches, like Boost or Varnish, even for anonymous users."

mkalkbrenner’s picture

The statement is not wrong and major difference compared to different modules.

ThemeKey distinguishs between cachable and non-cachable theme switches. And it supports time based cache clears: If you want the theme to be switched on Monday 8am, ThemeKey clears the caches for you right in time.

thanatoscries’s picture

try using themekey with cacheexclude module, helped fix my issue. In my case it was specific pages that needed to have caching disabled and this module helped

maustyle’s picture

All the D7 sites I worked on in the past 6 years have all caching enabled plus a standard mobile styled version based on css responsiveness. I would like to use theme key to switch to a mobile theme on a site that uses caching for anonymous users and js-css aggregation.
@mkalkbrenner do you (#3) mean that the mobile theme switch for cached sites can't happen at page request or that when you want to deploy another theme you can set the update via cron on Monday 8am?

mkalkbrenner’s picture

@maustyle:
Short answer: both.

For details open a new support request first! If you don't get email notifications on issue updates, nobody recognizes a comment on a closed issue.

suman.abc’s picture

Issue summary: View changes

When I faced this problem, I made a solution using varnish vcl script. In vcl_recv, I put a condition to detect mobile device using user agent - req.http.user-agent. Inside the if block I added an extra parameter for mobile version e.g. set req.url = req.url + "&mobile=true";. This extra parameter is only visible to drupal backend.
So when varnish calculates the hash using vcl_hash, it includes URL by default. Two separate URLs for desktop and mobile version make it happen to generate two cache entries for two versions whereas browser won't show these two separate URLs.