Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to serve different cached versions of a page depending on a cookie in Drupal?
    primarykey
    data
    text
    <p>The task is relatively straightforward:</p> <p>A Drupal website displays a list of articles with thumbnails. Some visitors would like to view it without images by clicking on a button/link and have that preference saved.</p> <p>e.g. <a href="http://patterntap.com/collections/index/" rel="nofollow noreferrer">http://patterntap.com/collections/index/</a></p> <p><img src="https://i.stack.imgur.com/1mosX.png" alt="alt text"></p> <p>The problem is all visitors are anonymous and given certain traffic, page cache is enabled.</p> <p>My idea was to use some simple JavaScript to set a cookie, refresh the page and depending on the cookie values (or its presence/absence) display or hide the images.</p> <p>Except Drupal serves cached pages quite early and the only quick way to modify the cached version that I could find is by hacking includes/bootstrap.inc and add a custom class to the body classes then hide the images with css.</p> <p>A very wrong approach, I know. But I wonder if there is a way to save different versions of a page and serve the correct version?</p> <p>Edit:</p> <ul> <li>need to keep the same uri</li> <li>the js to show/hide the images without reload and set the cookie is already in place</li> <li><code>hook_boot()</code> is not really called for cached pages, so can't do it via custom module</li> <li>.htaccess mods?</li> </ul> <p>Edit/solution: In the end went with Rimian's suggestion. But it is possible to accomplish the task using our own cache.inc implementation as seen in the <a href="http://drupal.org/project/mobile_tools" rel="nofollow noreferrer">Mobile Tools</a> module. Specifically, by extending cache.inc and updating settings.php to include</p> <pre><code>$conf['page_cache_fastpath'] = FALSE; $conf['cache_inc'] = 'path/to/my/module/my_module_cache.inc'; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload