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.
By Thana on
Hi,
Theme switching for desktop and mobile devices(ie: separate themes for deskop and mobile version) is not working as expected. After enabling the "Cache pages for anonymous users" enabled in [Site URL]/admin/config/development/performance.
Any suggestions to switch theme with cache enabled?
Thanks in advance.
Regards,
Thana
Comments
Boost mobile
A cached page is built using a specific theme, so of course what you want is not supported directly.
However, https://www.drupal.org/project/boost_mobile can add user-agent detection to your .htaccess file and transparently serve an alternate theme to users. In addition, because this is built on top of the Boost module, you're delivering pages directly from the filesystem and not touching Drupal and the database at all. As a result, your performance and especially scalability will be improved.
Theming switch
What kind of theming switching technique you are using ?? Could you please clear about that ..
Theme switching techniques
Earlier Switch theme techniques used :
1) https://www.drupal.org/project/mobile_detect - To detect the user agent
2) hook_custom_theme - To switch the theme in Drupal.
The above switching techniques working until the page is not cached.
Working Solution:
To work with varnish cache, changes are made in the VCL(Varnish configuration language file) returns the user agent dynamically
, switched the theme using hook_custom_theme and used DrupalFakeCache to serve the page from varnish.