I
I
Ivan Erokhin2019-04-28 13:15:55
Server optimization
Ivan Erokhin, 2019-04-28 13:15:55

How to cache a single wordpress template?

Good afternoon.
There is a site on wp, 500+ pages.
The main page for mobile devices should be different from the desktop version.
At what to differ cardinally.
Therefore, I decided to get out of this situation in this way:
In the main page template - page-home.php I wrote a simple condition:

<?php /* Template Name: Home */ ?>
<?php
if(wp_is_mobile()):
  include_once("page-home-mobile.php");
else:
  include_once("page-home-desctop.php");
endif;
?>

Now different templates are opened for different devices. But there were problems with the caching plugin (wp fastest cache), it cached the page and always gave one option: either the mobile version or the desktop. It shouldn't be like that.
Without caching, the download speed is not encouraging, as there are a lot of database requests on the page.
Is it possible to somehow cache individual php templates? Maybe there are more serious plugins that allow you to manage caching?
upd: "cached" means creating a static copy

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2019-05-30
@HeadOnFire

You will need to look at the caching plugin code and find the place where you can turn it on and help it understand that if we have wp_is_mobile() true, then we take (or create and take) the mobile cache, if false - the desktop one. If their caching method through mod_rewrite is used, then the settings of these rewrites will also need to be tweaked, at the server level you define desktop / mobile.
The description of the plugin says:
That is, the plugin already knows how to distinguish between devices, by definition. It might be worth looking to see if he has hooks there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question