1

I use AWS cloudfront with my drupal site. It sends below value with response headers.

CloudFront-Is-Mobile-Viewer => true

This value is true when you view your site with a mobile. And if this is true the site will load some mobile specific contents.

When using a browser, below response header will appear. And it'll show some desktop specific contents.

CloudFront-Is-Desktop-Viewer => true

Currently whether I open the web page from mobile or PC, the first one will get cached and it will show in the other device too.

How do I maintain two cache objects for this response headers value. One cache for mobile users and other one for desktop users.

I tried below with my_module.theme file

function my_module_preprocess_page(&$variables)
{
    $variables['#cache']['contexts'][] = 'headers:CloudFront-Is-Mobile-Viewer';
}

And once enabled the http.response.debug_cacheability_headers: true the response is showing like below.

enter image description here

But still the page caches for all the devices and looks like issue is not fixed.

  • 3
    Do you have the Internal Page Cache module enabled? If so you’ll need to disable it; it doesn’t respect cache contexts for anonymous users (by design, it’s just a reverse proxy) – Clive Mar 6 at 17:22
  • @Clive Man you saved batman :) – i am batman Mar 6 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.