0

I have a wordpress site. In my site there I have this one specific page that shows a lot of content. This content is based on many custom post types. I have built the page by writing a specific php file for that page called patio; i.e. page-patio.php.

The problem is that since the logic is complex it takes the server about 30 seconds to respond, I have optimized images and everything else that loads at the time; but I see that what takes too long is the server response.

I could try to optimize at server level, but I am seeing that it does not make any sense that all that complex logic and database reading should by done every time a user wants to display the page. The data changes once a day, maybe more often in the future.

I want to run a cron that executes a php snippet. Then that PHP snippet would prepare the page, i.e. write the html. So when a user clicks on the page I should just show that static html page and with javascript let him navigate the content.

Anyone found a solution for this?

  • Sounds more like a thing to maybe use Transients for … https://developer.wordpress.org/apis/handbook/transients/ – 04FS Sep 24 '20 at 12:46

2 Answers2

0

Good morning.

Is it a server problem, or number of CSS, JS and cookies? Is it a shared server?

Maybe you change your Theme for one that use pure javascript, or a few libraries JS and CSS be better. Be right about problem: if it's with server, or number of libraries and cookies, or both situation. However, if you can't change anything, you can contract a better server service for your application.

I gave up using wordpress to priorize page performance.

gmc_pecas
  • 25
  • 5
0

I was able to solve my issue very nicely, thanks to this 10 year old post:

Link to Stackoverflow post on saving to html page

I created a cron event that runs periodically that runs a PHP Snippet; I use the Code Snippet plugin to create the event:

if ( ! wp_next_scheduled( 'iKid_cron_twicedaily' ) ) {
wp_schedule_event( time(), 'twicedaily', 'iKid_cron_twicedaily' );

}

add_action('iKid_cron_twicedaily','iKid_Static');

And then the same plugin to create the iKid_Static function.

This function uses the ob_start() and file_put_contents('yourpage.html', ob_get_contents()) commands to write the html page on my server.

And then on my actual page I code:

$content = file_get_contents($cacheFile);
echo $content;

This way my users now get all the information on that page in just 2 seconds, down from about 30 seconds. I will be able to improve this surely when I move to a better server, but for now that is a great improvement for me.