WordPress Preloading Posts / Pages / Images – What, when and how!

Preloading posts is one of the popular recommendations by most articles on the internet on how to speed up your WordPress site. Since, most WordPress sites (I’d say over 99%) have little or negligible traffic, it is highly recommended to get the posts preloaded in the cache so that the visitors do not have to wait to get the generated on-the-fly that actually takes some time. In this case, by the time the post is generated to be served to the visitor, the visitors may have gone to visit another website. So, do I recommend preloading? Yes (for low traffic sites) and no (for high traffic sites). Read more for a bit of explanation on this…

Background

Lately, I was working with a high traffic website with over 25k posts and over 5k tags. I set up the server and everything was super smooth. Then I left it for a couple of days. When I came back and checked the server resource, the CPU usage was like 100+ (when accessed using the utility named top). It basically means the CPU was burning with no space to breath (or no real CPU for genuine requests). Upon investigating the issue, I noticed that a popular caching plugin that was supposedly make the site to fly like a rocket, with infinite number of options in it. One of them (do I name it?) was creating a huge number of requests to the server, every 500ms (that’s 2 requests per second).

The site may receive millions of hits per day. But, for any high traffic site, at any point, over 50% of the traffic would be towards less than 100 posts, irrespective of total number of posts. You could easily get the most frequently visited posts using your favourite analytics software.

What to Preload

As a rule of thumb, only preload the resources that are frequently accessed. Even if you don’t preload the frequently accessed resources, they get into the cache in no time, because they are frequently accessed. So, there is no point in using preload on a high traffic site. If you really want to preload, you may preload the top “n” number of recent posts. There is no point in preloading posts from previous years. Those posts may have lost their popularity by now.

Also, it is okay and is recommended to preload the sitemap. These days, most sitemap plugins generate the sitemaps on-the-fly. So, when your favourite search engine comes to check if you posted anything new, you wouldn’t want to let them wait. They are the most prestigious visitors (bots) for many web masters.

If you have a low traffic site, please ignore the above two paragraphs and go ahead and preload every post of your site. Your visitors (if any) will have better user experience and will probably come back (if you post regularly)!

When to Preload

The most neglected point when preloading is when to preload. Most plugins look at the sitemap and then preloads them in batches (at a rate of “x” number posts per minute, for example). So, when a sitemap gets updates, they may not start over immediately. They wait for the current routine to complete before they start over. So, the newly published post or recently updated post may not get preloaded. Those needs to be preloaded immediately. That’s where you can use a plugin such as preload full page cache plugin that actually fills the cache with the newly published posts or recently updated posts.

How to Preload

In general, most plugins deletes the existing cache and then starts to preload the post. So, if there are any visitors when the preloading actually happens, they may have to wait or they will access the same resource at the same time as others, resulting in multiple requests to the same post causing unnecessary overhead for the server resources (or to PHP in particular).

That’s why it is recommended to keep the existing cache while the new cache is being generated. WP Super Cache plugin does this correctly. Varnish does it correctly too. Of course, both needs to be tweaked to make this to work.

I hope this has given you some insights on how preloading works in general in WordPress and how to make use of it effectively. If you have any particular question, please feel free to ask in the comments!

Leave a Reply

Your email address will not be published. Required fields are marked *