Is there a recommended method for using varnish with mobile_tools? I would be very interested in this, and don't mind looking into developing a plugin module if required. On one of our current sites, we have varnish letting mobile devices through (with a header to confirm varnish has okayed it to prevent accidental caching of the mobile site to desktop users). The custom module then checks this header, and sets a relevant cookie for the device, on future page loads, this cookie is then used to cache variant version of the site.

This cookie can also be set to 'desktop' by clicking a link within the site, allowing a mobile user to choose to view a desktop version of the website. The module does a few other bits, but these are the main pieces of functionality we would require.

I was hoping to get peoples thoughts on this, and whether there is already a working method for this?

Thanks,
Dan

Comments

rasmusluckow’s picture

Subscribing.

vinmassaro’s picture

Also interested about using mobile_tools from behind a reverse proxy.

cayenne’s picture

subscribing too!

seakayjay’s picture

Interested. Subscribe!

dabblela’s picture

Bump with an interesting article here:

http://fangel.github.com/mobile-detection-varnish-drupal/

I haven't looked into mt much (yet) but I wonder if some combination of the above method and an implementation of hook_is_mobile_device() might be enough?

askibinski’s picture

@manatwo

thanks for that article it helped a lot!
And you are right, using the VCL code in that article and a little code in your own module, detection works.

Based on that code you can use hook_is_mobile_device together with hook_device_groups to do something like this:

function YOURMODULE_is_mobile_device() {
  if (isset($_SERVER['HTTP_X_DEVICE'])) {
    switch ($_SERVER['HTTP_X_DEVICE']) {
      case 'mobile-tablet':
        // Show the tablet-theme
        $mobile_browser = array('type' => 'desktop', 'group' => 'mobile-tablet');
      case 'mobile-smart':
        // Show the smartphone-theme
        $mobile_browser = array('type' => 'mobile', 'group' => 'mobile-smart');
      case 'mobile-other':
        // Show our theme for other mobile devices
        $mobile_browser = array('type' => 'mobile', 'group' => 'mobile-other');
    }
  }
  return $mobile_browser;
}

/**
 * Implementation of hook_device_groups
 * This is called by Mobile Tools to learn about the available device groups.
 */
function YOURMODULE_device_groups() {
  return array('mobile-tablet' => 'Tablet', 'mobile-smart' => 'Smartphone', 'mobile-other' => 'Other');
}

Now, just as stated in the article, the detection is pretty basic but you could expand on that by extending the VCL file.

udvranto’s picture

Subscribing