Disable cache for pages requiring mobile detection

Created on 23 November 2024, 25 days ago

Problem/Motivation

Blocks on the home page of my site use Mobile Detect module to present content to users which is dependent on the device used to view site. This functionality doesn't work when Advanced Varnish is enabled.

For the mobile-aware blocks on the front page I checked ESI block and chose 'no-cache'. This had no effect once the page had been loaded once. The same cached version was always loaded subsequently, whether in mobile or desktop view.

I tried adding the home page to the 'Excluded URLs' list. This disables Varnish for the whole site. Can I specify the page somehow? I tried adding /node/x for the node which is used as the home page, and also using its alias.
I also tried turning off cache for the content type used for the front page, using Adv Varnish settings in content type.

Steps to reproduce

Enable Advanced Varnish and Mobile Detect modules.
Add two blocks to site home page, use Mobile Detect block configuration options to set one which shows only on phones, and one which shows only on desktop computers.
Check the ESI block, 'nocache' option for both blocks.
Enable ESI in Advanced Varnish configuration page.
Load front page in browser. The device used to load the page determines cached version of page for all devices thereafter.

Proposed resolution

Ideally the fix should be at the level of blocks, which are set not to be cached.

💬 Support request
Status

Active

Version

4.0

Component

Code

Created by

🇬🇧United Kingdom mike-kelly

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024