Search code examples
drupal-6varnishpressflow

Using mobile tools module in Drupal6 with varnish?


Can we use Mobile Tools module in Drupal6 with Varnish? I doubt varnish will cache the index page and will not allow redirection to mobile version of the page.

Any work arround?


Solution

  • You want to make your server return different responses based on the used device/browser. This means your pages 'vary' based on the used User-Agent http request header, and in theory you should instruct any http proxy/cache in between to only use a cached version if the User-Agent string is the same by adding a http response header:

    Vary: User-Agent
    

    However, because browsers like Internet Explorer (unlike Chrome) use many slightly different User-Agent headers, this will completely kill your cache hit ratio. You need a smarter cache to understand that Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0) for your purposes is equal to Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.0; Trident/4.0; InfoPath.1; SV1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 3.0.04506.30), or any other user-agent string used by a desktop browser.

    There are two options for you to solve this with Varnish:

    1: Do mobile user-agent detection yourself in varnish logic, the same way mobile tools does it. E.g.:

    vcl_recv {
      if (req.http.user-agent ~ 'ipad|ipod|iphone|android|mini opera|blackberry|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|pda|psp|treo') {
        hash += "mobile"
      }
    }
    

    2: Or, always set a session cookie mobile=true or mobile=false after you've seen the first request, and only serve cached pages for requests with this cookie.

    And after googling a bit, you should read: http://fangel.github.com/mobile-detection-varnish-drupal/