0

I am using updated 4.7.3 wordpress with wp-touch pro and varnish latest vrsion (5)

when i logged in to wordpress dashboard theme switch between desktop theme to mobile and vice versa works well

but when i logged out it is not working .

varnish code

  if (req.url ~ "\?wptouch_switch") {
        return(pass);
    }

i suppose it wptouch switch is not passed through varnish .but even used above in my vcl .still its not working.

wptouch theme switch

2 Answers2

2

The code above only makes sure that the switch URL isn't cached. However you should understand that you have to cache mobile and desktop versions of the same URL separately. That means different hash in Varnish VCL for mobile and desktop devices.

You should implement this similar to this config:

# The data on which the hashing will take place
sub vcl_hash {
    # ....
    if (req.http.X-Device ~ "smart" || req.http.X-Device ~ "other") {
        hash_data(req.http.X-Device);
    }
    # .... 
}

Naturally, that alone is not sufficient. You need to also copy other relevant parts for setting X-Device which are located in sub detect_device procedure.

Danila Vershinin
  • 8,725
  • 2
  • 29
  • 35
  • Thank you Daniel , actually i forgot to add devicedetect.vcl after calling it works . i have also added vary header to sub vcl_deliver so it will cache both version of same website and server separately. – Biswajit Mohanty Apr 04 '17 at 07:25
0

ADD device detec vcl to same folder as default.vcl

add below in default .vcl

sub vcl_recv {

call devicedetect;

if  (req.http.Cookie ~ "wptouch-pro-view=desktop" ) 

      {
                        return(pass);     
      }

}

sub vcl_hash {

   if (req.http.X-UA-Device) {
      hash_data(req.http.X-UA-Device);
   }
   if (req.http.wptouch) {
      hash_data(req.http.wptouch);
   }



}



sub vcl_deliver {


if ((req.http.X-UA-Device) && (resp.http.Vary)) {
        set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device", "User-Agent");
    }
}