Most common reason for this is, because your website is getting cached, and you'd need to either clear it every time you apply a change or bypass it, which is also the more convenient and efficient way. We'll show you how you can achieve this on WordPress websites as you read on.
What is a Wordpress cache?
Website cache in general, is a temporary storage location for static content like HTML, CSS, JavaScript, and more. The purpose of a cache is to store copies of webpages for future requests.
In other words, when a visitor comes to your website, their browser will send requests for resources to your website’s hosting server and then store those resources locally. Furthermore, when that same visitor comes back to your website again, their browser will serve resources from the local cache rather than making requests to the server, which will make the page loading process on their end much faster.
We can utilize two different types of caching
- Client-side caching, which is the type of caching we described above, where data is stored locally in the browser cache
- Server-side caching, which works similarly to client-side caching, the difference being that the cached data is stored on a server
How to display the latest version of your Wordpress website?
Whenever we’re making changes to a website, it’s important that we’re not being served with cached files as it may trick us on our end, while new visitors are being served with a broken website.
Furthermore, there are a few different options we can choose from, which may include bypassing caching plugin effects, purging currently cached data, or disabling cache altogether.
Bypass caching and optimizations from Wordpress plugins
One of the most popular caching and performance optimization plugins like WP Rocket, may offer a convenient way to display a version of a webpage where none of the effects of the plugin will be applied.
In WP Rocket plugin’s case, all we need to do is add a custom “?nowprocket” query parameter at the end of a webpage’s URL address. However, you need to keep in mind that not all of the popular caching plugins will offer this kind of functionality.
Clearing cache in Wordpress websites
One of the most popular choices when it comes to displaying the latest version of a website, is to delete all cached files. Furthermore, when it comes to Wordpress sites, we can go about this in a few different ways.
Plugins
First of all, we can choose between a number of different caching plugins that will do the heavy lifting for us.
We’re going to list just a few of the popular ones here
- WP Rocket
- WP Super Cache
- W3 Total Cache
- Litespeed Cache
All of them have easy to use UI, giving you the option to purge cache either for the entire website or just certain pages of your choice.
Furthermore, if you’re using a content delivery network (CDN) service like Cloudflare, you can also purge cache from there. You need to keep in mind that when you’re using various different caches for your website, you need to clear all of them.
WP-CLI
Another way to clear cache from a Wordpress site is to use WP-CLI. This option is more suitable for those who are more comfortable with working with a terminal.
First thing you need to do is login to your Wordpress site via SSH. After you successfully establish a connection, you’ll need to navigate to the home directory of your site. And lastly, you need to run the following command.
wp cache flush
Disabling caching using custom headers
Wordpress has a dedicated filter for cache-controlling HTTP headers, which we can use to prevent caching. Furthermore, we need to add various different headers for this purpose, so we include various ways how different browsers handle cache prevention.
The filter we’re talking about here is called nocache_headers, and the following example shows how to use it inside functions.php file.
add_filter( 'nocache_headers', function() {
return array(
'Cache-Control' => 'no-store, no-cache, must-revalidate, max-age=0, some-custom-thing',
'Pragma' => 'no-cache',
'Expires' => gmdate( 'D, d M Y H:i:s \G\M\T', time() )
);
} );
Conclusion
To conclude, we talked about what the caching is for and why it’s important for user experience of your visitors, while also why it’s important to know how to remove its effects and how to do it.