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

yelvington’s picture

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.

nitin.k’s picture

What kind of theming switching technique you are using ?? Could you please clear about that ..

Thana’s picture

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.