1

I'm currently running Magento 1.7 with Varnish Turpentine.

I have noticed a strange behavior on cached content - Varnish returns same content for mobile and tablet(iPad), although in Magento back-end I have set design exceptions for matched expressions (iPad should use default, mobiles use mobi) and it works like a charm until varnish default.vcl is applied.

After checking around I found out that varnish use device detection and normalizes user-agent as per following:

if (req.http.User-Agent ~ "iP(?:hone|ad|od)|BlackBerry|Palm|Googlebot-Mobile|Mobile|mobile|mobi|Windows Mobile|Safari Mobile|Android|Opera (?:Mini|Mobi)") {
set req.http.X-Normalized-User-Agent = "mobile";

Well, fair enough... clearly mobiles and tablets will return same cache hit as both are normalized as mobile ... lets separate iPad I though

if (req.http.User-Agent ~ "iP(?:hone|od)|BlackBerry|Palm|Googlebot-Mobile|Mobile|mobile|mobi|Windows Mobile|Safari Mobile|Android|Opera (?:Mini|Mobi)") {
set req.http.X-Normalized-User-Agent = "mobile";
else if (req.http.User-Agent ~ "iPad") {
set req.http.X-Normalized-User-Agent = "ipad";

A big surprise after this change was that varnish still returns same cached content.

I have tried to use different varnish device-detects but all unfortunately failed.

Have anybody has a smallest clue what could be the issue?

  • After you made the change to separate iPad, did you apply those VCL changes to the running instance of Varnish? – Aric Watson Mar 31 '16 at 15:48
  • Hi, thank you for your time helping to sort this out. Yes, I did apply changes to running instance, also I tried to restart varnish on the server and applied changes on running instance afterwards but both returned same issue. – Aivis Zvezdovs Mar 31 '16 at 18:33
  • Ok, perhaps try turning off the Normalize User-Agent option in Turpentine as a test and see if that works? – Aric Watson Mar 31 '16 at 18:55
  • Hi, once Normalize User-Agent option is turned off, cache serves one content for all devices (even if I apply new config). Also I noticed that if Normalize User-Agent option is on and I delete all entries regarding device detection and apply it, cache still serves different content for mobile agent and pc agent. – Aivis Zvezdovs Apr 1 '16 at 9:45

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.