Cache for mobile theme:

Posted in: Newspaper
Post count: 6

Hi,

I’m using mobile theme, but there’s some problem when I use page caching. (I use Fastcgi_cache with Nginx)

If I enable the cache, the mobile theme will not show up. It shows original mobile layout instead.

But if I cached mobile theme first, the desktop version is gone, vice versa.

Is there any solution? Thank you!

Post count: 20685

Hi,

The mobile theme is sensitive when it comes to caching. It is compatible with the WP Super Cache which is the only caching plugin we have tested up to this moment
https://forum.tagdiv.com/the-mobile-theme/
You could consider using that caching plugin, or deactivate the mobile plugin which is not working properly in those circumstances.

Thank you!

Post count: 6

Hi Simon,

I have figured out the solution, provide as below:

When you set a FastCGI cache, make sure add a variable to specify agent, for now I’ll use $mobile_request

And we can add the code to http block:


set $mobile_request 0;

    if ($http_user_agent ~* "(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino") {
        set $mobile_request '1';
    }

    if ($mobile_request = '1') {
        set $skip_cache 1;
    }

next, find your fastcgi_cache_key section,
then add $mobile_request to the end of code.

For example:


fastcgi_cache_key "$scheme$request_method$host$request_uri$mobile_request";

This should be working, just remember to reload the NIGNX server.

Hope this helps.

Post count: 20685

Thank you for posting this solution, it may be helpful for other users in similar situations.

Post count: 127

I,i have same problem with my cache.
When i enable cache with SG SUPERCACHER of Siteground mobile theme not show.
Any ideas?
Thanks

Post count: 20685

@Ginfox Maybe Atelier Shen can help you with more on the matter if related to his solution. I would have nothing to add unfortunately, we have not made any tests with a different caching system up to this point.

Post count: 6

Hi Ginfox,

I have found a solution on WordPress.org forum, post by staff of SG. You can try this out:


function add_vary_header($headers) {
$headers['Vary'] = 'User-Agent';
return $headers;
}
add_filter('wp_headers', 'add_vary_header');

Add code above to your function.php file in Newspaper-Child theme folder. This will make different cache for each device.

Sorry I didn’t use SiteGround for a long time, so I’m not able to test for you. But I guess you may reply to https://wordpress.org/support/topic/configure-mobile-theme-for-supercacher-siteground/ if you need further support.

Happy Coding!

Atelier Shen

Post count: 127

Thanks Atelier for your interesting, but i not solve….
Thanks

Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic.