How to set up W3 Total Cache caching for WordPress
13:42, 27.09.2022
One of the most difficult plugins in terms of configuration is W3 Total Cache. At the same time, it is extremely useful for all WordPress sites, as it significantly increases the speed of the resource, reduces its loading time, and reduces the overall server load. After spending a little time studying this material, you will be able to figure out how to configure the W3 Total Cache caching plugin for WordPress.
How to install W3TC
Everything is as usual: through the admin panel, go to the "Plugins" tab and add a new one – through the search, we find W3 Total Cache and connect it. Before installing, be sure to remove any other caching plugins if you have used something similar before.
Basic settings of W3 Total Cache
In the left menu of WordPress you will see the Performance tab – go there and click on General Settings. Here we will go through the main points that need to be configured:
General
Preview mode – enables or disables preview mode. When this option is active, the plugin works only for the user who configures it. It will be useful for those projects that have been online for some time and have accumulated some traffic.
Page Cache
The most important option, the inclusion of which activates the caching mode of web pages. This, in turn, reduces the server response time and increases the page loading speed.
Also here you can choose the method of caching site pages in the Page Cache Method item. We recommend installing Disk: Enhanced, since in this case the cache data will be stored on the server drive – as a rule, it is an SSD. Solid-state drives are extremely fast, so they are ideal for cache storage – reading this data will take fractions of seconds, so the benefits of the technology will be felt even more. You can also choose the method of storing the cache in RAM – it is even faster, but this is very wasteful since RAM is expensive and its volumes are limited. The method of caching using RAM is suitable only if your server has an excess supply of RAM.
Minify
Here we have 3 items that require setting up:
- Minify – activates the minification of the file code. The minification process involves reducing the size of the source code by removing unnecessary characters and comments without compromising functionality. In practice, it provides an increase in site loading speed by compressing CSS, JavaScript, and HTML.
- Minify mode is recommended to be set to Auto, since in this case W3 Total Cache will independently determine the files that need to be optimized in terms of code, and will also automatically set the order of file connections.
- Minify Cache Method – caching method. As in the case of Page Cache, the recommended value will be Disk – provided that you have an SSD or NVMe drive installed on the server.
As for the HTML minifier, JS minifier and CSS minifier items, the default value will be recommended for all three.
Opcode Cache
An option that activates caching of compiled PHP code. We recommend installing Opcode: Zend Opcache, as this is the best option for VPS. There is also a Validate timestamps item here – we mark it with a checkbox so that the cache is updated correctly without having to restart the PHP module.
Database Cache
Enables caching of database requests. In practice, it reduces the time for generating website pages, and is an excellent alternative to an object cache when, for some reason, the latter cannot be used. You can use both technologies in parallel.
In the same tab, you can select Database Cache Method – Memcached will be recommended. We have a separate article about Memcached technology, we recommend reading it. In general terms, this technology allows caching data in RAM based on hash tables.
Browser Cache
This item is responsible for client caching, which speeds up the loading of sites upon repeated request by caching graphic elements, CSS and JavaScript.
Cache Preload
Here you can set the interval between cache updates, as well as specify the number of pages that will be cached at specified intervals. The higher the server capacity, the more pages should be specified, but you can only determine the optimal figure for your site by experience.
Purge Policy: Page Cache
In this block, you can configure the mechanism for clearing the cache when creating and editing records, as well as when publishing comments. It is best to leave the default values.
Advanced
In the advanced settings, the field of interest is the Garbage collection interval, since here we can set the interval for clearing the cache on disk. The higher the workload of your project, the lower the value should be set – this will allow you to get rid of the expired cache in a timely manner so that it does not overload the file subsystem.
Minify
Here we can configure the minification of HTML, XML, CSS, and JavaScript. To begin with, go to General and activate the following options:
- Rewrite URL structure – allows you to disable GET parameters for links;
- Disable minify for logged-in users – with this option, you can disable the loading of compressed pages for users who have been authorized;
- Minify error notification – setting up error alerts when generating a minified cache.
HTML & XML
In this block, we can configure the minification of the HTML code of the site pages. As practice shows, you will not get a serious performance gain from compressing HTML code, but activating this option can lead to problems with layout. Use at your own risk.
JS
It contains minification settings for JavaScript files. To activate the option, check the box next to Enable. Next, you can set script loading parameters for different areas of the HTML page. The optimal value is Default. You should also choose a minification mechanism – it is best to put Combine only.
All other settings in this section can be left untouched.
CSS
Activate the W3 Total Cache minification, check the box next to Combine only, and do not touch anything else, there is no need.
Connecting Google Page Speed to W3 Total Cache
To enable Google Page Speed, you need to check the box next to "Enable Google Page Speed dashboard widget". Then you need to click on the "API key here" and paste it into the appropriate field. The key itself can be obtained on the official website. After saving the settings, go to the Debug section and disable all debugging options, since activating them only adds unnecessary code to your site. For the purpose of optimization, we disable it.