Nginx fastcgi_cache and Wordpress wp_is_mobile function - not showing correct page versions to correct user devices

First off I want to say what an amazing and easy piece of software you have created. It has saved me so much time and frustration it’s unbelievable.

I installed a Wordpress site with WPFC / nginx fastcgi_cache. It’s running fast and I’m pleased.

I am however having one issue. I have lots of references to wp_is_mobile and ! wp_is_mobile through my theme files http://codex.wordpress.org/Function_Reference/wp_is_mobile This means if a visitor is on a mobile, I can show them a 320x50 ad for example, versus a 728x90, etc and make other layout changes (ie use it in widgets too). It’s very useful for me.

I’ve noticed with the wpfc cache though, that it will only cache whatever version of the page gets hit first. So if a mobile user hits a page first, the mobile version of the page will be cached and shown to all mobile and all desktop users. Obviously this is not ideal.

So my question is, does anyone know of a fix for this so that somehow the right version of the page can be shown to mobile or desktop users

Right now I have turned off WPFC by making $skip_cache 1; in wpfc.conf and it is working fine.

Thank you!

PS: If this cannot be resolved, am I best off enabling all cache options in W3 Total Cache? At the moment I only have object and database caching enabled (memcached).

Page cache on W3 Cache seems to have the same issues. Nevertheless the site is still running faster than ever on Nginx + DB and Objects cache via W3.

I would love any sort of assistance on my first question though!

Last bump on this one!

@mdotk

Sorry for this late reply.

You can set cookies for according to detect which device is accessing your site, and make your cache key accordingly nginx to serve from.

Thanks for this, might you have a link to the documentation for implementing it?

@mdotk

I have no perfect link describing it, but this dicussion might help you

https://wordpress.org/support/topic/plugin-w3-total-cache-w3tc-rules-with-nginx-potentially-causing-interminent-infinite-loops

More mine and anyone else who wants to do this, this was the solution:

https://www.alpine.link/wordpress-page-caching-mobile-users/