Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I use theme key to switch the theme for mobile devices. When Drupal Cacheing is enabled, Theme Key fails to switch the theme.
Comments
Comment #1
mkalkbrennerThat'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.
Comment #2
info@cgfix.com CreditAttribution: info@cgfix.com commentedOh 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."
Comment #3
mkalkbrennerThe 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.
Comment #4
thanatoscries CreditAttribution: thanatoscries commentedtry 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
Comment #5
maustyle CreditAttribution: maustyle commentedAll 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?
Comment #6
mkalkbrenner@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.
Comment #7
suman.abc CreditAttribution: suman.abc commentedWhen 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.