Profile

Pure Dry Goods! Caching plugin W3 Total Cache setup tutorial (Pro), illustrated, bypassing dynamic cache

Search
W3 Total Cache setup tutorial
Article List
Article List

W3 Total Cache Pro(W3TC is an old caching plugin, the free version has more than a million installations and many good reviews. w3tc is comprehensive and powerful, can be very delicate control of cache content, accelerate the effect is very good, can do many other caching plug-ins can not do things.

W3TCDynamic content caching can be bypassedIt has object cache, database cache, fragment cache, shrink HTML/CSS/JS/etc. to greatly reduce the burden on the server to shorten the page load speed. It is a really useful caching plugin, this site uses W3 Total Cache Pro (Click to download) acceleration.

Once this site started usingWp RocketSpeed up, but the visitor login still shows not logged in status (avatar and other content is not displayed). Later, I tried Fastest Cache, Super Cache and other plug-ins, but still could not log in properly. Finally, I usedW3 Total Cache ProThe perfect solution.

It is not as famous as Wp Rocket or Fastest Cache because there are too many setting options and many people don't understand the settings, so it is not as effective as Wp Rocket, but in fact it is better than Wp Rocket if used properly! The purpose of writing this tutorial on W3 Total Cache settings is to help you understand and make the right settings for your website.

W3 Total Cache is not as popular as other caching plug-ins in addition to the complicated settings and another reason is that it does not have the ability to generate critical CSS and delay loading JS, which leads to a poor result. Suggestions withPerfmatters Asset Cleanup PluginUse, the 2 together definitely function and effect better than Wp Rocket.

Note: For Nginx systems, if you change the W3 Total Cache settings, you will need to restart Nginx if the contents of the nginx.conf file have changed.

 

W3 Total Cache setup tutorial

The situation varies from site to site, the following settings are for reference only.It is recommended to keep the default settings if you don't understand themIf you use the free version, there is a high probability that there will be no error. The following screenshot of the setup tutorial is the W3TC Pro interface, if you use the free version some features will show disabled. If you have questions, welcome to leave a comment below. First understand some basic concepts.

Page Cache - When visitors access a page, the server needs to query the database and run a script to generate the input page. Turning on page caching will store a copy of the completed page, and subsequent visitors can access the page copy directly without querying the database and running scripts, thus greatly reducing page load time and server pressure.

Opcode Cache - Cache the results of compiled PHP code, making subsequent requests for the same PHP code faster.

Fragment Cache - A page may be some of the content is dynamic , if the use of page caching default dynamic content will become static can not be updated in a timely manner.Fragment Cache role is through the use of PHP templates inside the specified code wrapped in dynamic content plate , so that the page cache bypasses the cache this part of the dynamic content only cache other content , especially suitable for e-commerce or membership site .

Fragment Cache can only be used in PHP templates, the use of the scope and conditions are more limited, click theSee how the fragment cache is specifically used.

Note: Enabling fragment caching may result in editing functions.php and other files can not be saved, first temporarily disabled, edit and then open or insert the code with the plug-in instead (not using functions.php).

Object Cache - Cache the results of completed database queries. While page caching can greatly help reduce site response times by caching static pages, there are still many uncached object requests. Object caching will further improve performance by caching these objects.

Object caching allows to fetch data from the database more efficiently. Its purpose is similar to that of a database cache. However, object caching is more efficient compared to database caching because it allows to handle fewer requests.

The idea behind object caching is that WordPress core, themes and plugins can store some frequently accessed and rarely changed data in an object store. This eliminates the need to retrieve and process these objects on every request. Ultimately, object caching will reduce the total number of database queries required per page, and your response time will be reduced because the CPU doesn't have to rebuild these blocks of data.

Database Cache - Caching MySQL database query results helps free up MySQL server resources taken up by repeated queries that return the same data each time so that it has more capacity to work with truly dynamic data.

Although the object cache will store executed PHP, it may not contain information retrieved from the database and will not cache most calls to the database. If there are many database queries being executed after object caching is enabled, database caching should be enabled, and vice versa is not recommended.

Database caching is not compatible, and many hosting vendors recommend disabling it. If there is a problem disable it and try it.

To sum up: object caching is a supplement to html page caching, catching the missed fish (some dynamic requests that are not cached), while database caching is a supplement to object caching, catching the missed fish (some object requests that are not cached).

Under normal circumstances, both object caching and database caching should be enabled, but the server memory and database conditions vary, and sometimes querying content directly from the database can be faster than memory and disk queries. Therefore, you need to use the W3TC setup guide to test the actual effect of different caches and then set them according to the situation.

Browser Cache (Brower Cache) - This puts a copy of the page into the user's browser cache. When that user revisits the same page using the same browser, it will be loaded from the cache stored on their computer, rather than querying the web server.

Disk: Basic - This method will call a PHP script to serve the cached page.

Dick: Enhanced - This method will modify the .htaccess file to direct Apache to a static cached version of the page, and is therefore faster than Disk and is recommended. If the site slows down, use Disk: Basic instead.

Dick (disk) cache- Store the cache file on disk.

Memcached Cache - Storing cached files in memory is faster than Dick (disk) cache in most cases. ViewDick cache and Memcached cache speed comparison.

Tips: The disk read/write speed of shared hosting (server) is generally limited and will not be fast. Therefore, if you enable database caching or object caching methods for shared hosting, try not to choose disk, and recommend choosing memory (Memcached/Redis).

 

Setup Tutorial.
First use the Setup Guide to test the settings suitable for your website, click "Setup Guide" to enter the quick setup guide. Note: The actual access speed of the front desk must prevail, this test may not be accurate. After setting up the test, the speed is slow to change the settings or disable the database cache and object cache function.

Pasted 78

Tap "Next"↓.

Pasted 33

Point test page cache↓

Pasted 79

Select the one with the shortest time. Tap "Next" for the next test. AllAfter setting up, if the website access speed becomes slow, try to change the page caching option. We had a site that was very slow with Disk: Enhanced, so we changed it to Disk: Basic and the speed went back to normal.

Pasted 80

Pasted 33

 

It is not recommended to enable both database caching and object caching at the same time, there may be bugs and the speed will be slower, just enable one. If the site slows down after enabling one of them, disable both caching functions.

If you decide to enable database caching, regardless of the results of the test, select the memory cache (Memcached or Redis) is more effective and stable. Click "Next" when you have made your selection.

If you are using shared hosting like SiteGround, CPU and memory may be severely limited, and the database caching method may be slower if you choose memory (Memcached/Redis), so the host chamber recommends choosing "disk" for the caching method.

Using the on-disk method of caching the database on shared hosting may slow down the site, as it is faster to fetch data from the database than to fetch cached data from the disk. In summary: It is recommended to disable database caching if you use shared hosting, it may be faster.

Pasted 82

 

Object cache test result shows that None time is the shortest, select "None" and click "Next". If you disable the database cache (the above test results choose None), the object cache test results will be completely different, if you enable the object cache is generally recommended to choose Memcached (pagoda panel need to install Memcached extension in PHP first).

 

Pasted 81

 

Select "Enabled" for browser cache and click "Next".

Pasted 83

W3TC's delayed loading compatibility is not good, many people in the forum posted that the image display exceptions after enabling. It is recommended to usePerfmatterss image delayed loading feature instead (works best). If you already use delayed loading in other plugins, don't enable it here, otherwise enable it. Tap "Next" and then "DASHBOARD" to go back to the dashboard.

Pasted 84

This is the end of the setup wizard. If you are not a shared host, it is best to restart Nginx for the settings to take effect. Let's start setting up General Settings.

 

General Settings Settings

Page Cache is already enabled in the setup wizard and the caching method is selected, so no additional settings are needed, just skip it.

Pasted 123

 

Minify according to the chart settings, Minify mode must choose Manual, if you choose Auto site display a high probability of problems. minify Cache Method choose Dick safer, choose other easy to error. The other three items are selected according to the figure, here only use the W3TC compression function, its delayed JS / CSS function is not compatible with the effect is generally not recommended to choose.

Pasted 124

 

Opcode Cache is set up as shown↓.

Pasted 125

 

The database cache, object cache and browser cache have been set up in the setup wizard above, so just skip it here and leave it alone. If you don't enable database caching later, remember to go back here to enable database caching instead, and choose Memcached for Method.

Pasted 126

Pasted 127

Pasted 128

 

If you use a CDN you need to change the resource URL inside the html to a CDN URL so that you can load resources from the CDN. plugins like Wp Rocket and Perfmatters have a CDN rewrite URL function. Just enable this feature in a plugin, do not enable it in more than one plugin, there will be conflicts.

We used W3TC's CDN function to rewrite the URL and found that Perfmatters' used.css generated by deleting useless CSS could not be loaded, prompting URL errors. After using the Perfmatters CDN function to rewrite the URL, we found that the used.css generated by deleting useless CSS could not be loaded, indicating an error in the URL. Try not to use the CDN function of W3TC if you have the option.

If only W3TC this plug-in has CDN function, then use it. Use domestic Tencent cloud, seven cattle cloud and other CDN choose "Generic Mirror"↓.

Pasted 129

 

Reverse proxy is a reverse proxy that sits between the web server and WordPress and can be used to perform various logic-based operations on incoming requests. Don't touch it if you don't know what it means, just skip it.

Pasted 130

 

Message Bus is not used by the vast majority of people ↓, if you do not understand what it means directly skipped.

Pasted 131

 

Leave the User Experience settings as default and just skip them. Here you can enable delayed loading of images and Google Maps and disable emoji. These features are available inPerfmatters PluginIt's all there and works better.

Pasted 132

 

Statistics analyzes site and server caches and is used to track the size, timing, and hit/miss rates of each cache, providing the information needed to get the best performance. When enabled, Statistics inside W3TC settingsPasted 146tab to view the information.

Enabling it will add a little bit of server load, enable it on demand.

Pasted 133

 

Fragment Cache is enabled ↓, select Memcached.

Pasted 134

 

Miscellaneous all options to keep the default, just some auxiliary role, if you do not understand directly skip better.

Pasted 135

 

Debug debug mode↓ allows you to disable specific caching layers and optimization settings. For example, if you notice a visual glitch on your site, you can enable debug mode for the "Minify" option, which will insert HTML comments into the source code of your page to help you troubleshoot.

If you find any problem with any cache, check the corresponding cache point in the following settings to save it. The debug mode feature puts extra load on server resources, so it is recommended to use it only during low traffic hours and remember to disable debug mode after troubleshooting is completed.

Pasted 136

 

Import / Export Settings is the export and import settings, which you can understand at a glance.

Pasted 137

This is the end of the General Settings settings, and the following are the detailed settings for each function.

 

Page Cache Settings

Set the page cache here, just set it as shown.

Pasted 138

 

The Aliases feature allows caching of the same WordPres content available on different domains (e.g. domain.com and www.domain.com). We do not recommend enabling this feature, if there are different domains the best way is to 301 redirect to the same domain to avoid theDuplicate content penalty.

Pasted 139

 

Cache Preload is the cache preload function, set it according to the picture, enter the full URL of your site map (.xml ending) in the red box. Other keep the default, if the preload interval is too short will lead to high server load.

Pasted 140

 

Purge Policy: Page Cache is to set when the site page cache should be automatically purged. If you don't know what to choose, follow the settings below to use most sites. The cache will be automatically purged when a page/post/listing page is modified or a new comment is added to a post.

Pasted 141

The following chart does not check the items that are not useful, Blog feed is also, not recommended to check.

Pasted 142

 

REST API ↓ Set whether to cache REST API, REST API allows you to query JSON format data, it is recommended to select "Don't cache'". We previously selected "Cache" led to the failure of the WeChat Public custom reply function, select "Disable REST API" led to hide the content protection plug-in function is abnormal.

Pasted 143

 

Advanced settings, except those mentioned below, are recommended to be left as default.

Late initialization and Late caching are only available for some plugins in some cases, and do not need to be enabled in most cases. If the General Settings inside the Cache Page Method: select "Disk: Enhanced", Late initialization and Late caching are not available. Just change it to "Disk: Basic".

Late initialization.That is, delayed initialization is a method of initializing an object in programming. An object is created in memory only when another object references it. Delayed initialization relies on the fragment caching feature, so do not enable it if you are not using fragment caching.

Late caching.i.e. Deferred Cache, is a way to delay caching pages. It allows partial loading of WordPress content before the cache is processed by W3 Total Cache. Deferred caching can be used in some specific cases, such as for geolocation purposes. It does not need to be enabled in the vast majority of cases.

Compatibility mode. If you choose Dick: Enhanced for caching, a Compatibility mode option will be added under Late caching. The official recommendation is to enable this feature only when you encounter problems related to Apache rules, and the performance will be reduced by about 20% after enabling it.

Pasted 229

Pasted 144

Rejected cookies↓: Enter the cookies for the content that needs to be bypassed in the cache, one per line.

Never cache the following pages↓: Enter the URLs of the pages that do not need to be cached, one line at a time.

Pasted 145

 

Minify Settings

Set the compressed HTML, CSS, JS details, here if the settings are not correct site is prone to display errors, set it according to the chart. If the site displays errors, pay attention to disable the option to exclude.

Pasted 26 

Pasted 27

Pasted 28

Pasted 29

 

Database Cache, Object Cache, Fragment Cache

The settings inside these 3 tabs can be left as default if you don't know what they mean.

Database Cache (database cache) and Object Cache (object cache) are quite useful and may cause website problems in some cases. For example, the database cache may lead to high CPU usage, if the problem disables these 2 functions one by one to troubleshoot the problem.

After enabling Object Cache, if the website background plug-in settings, article editing and other functions appear abnormal, switch to Database Cache or turn off the function to try.

 

Browser Cache

Set ↓ as shown. If your site has dynamic content do not want to be cached, the following three red content do not check, otherwise check the box.

Pasted 148

Pasted 149

 

CSS & JS settings follow the chart below.

Pasted 150

 

HTML & XML settings according to the following chart, if your site has dynamic content do not want to be cached, the following three red content do not check, otherwise check the box.

Note: The Set cache control header below is sometimes automatically enabled after modifying other WT3C settings or upgrading the plugin, causing some dynamic content to be cached. To bypass dynamic content caching, check this item every time you upgrade the W3TC plugin or modify the configuration to keep it disabled.

Pasted 151

 

Media & Other Files is set as below ↓, other options remain default.

Pasted 153

 

Security Headers don't help much with speed, but they can improve site security.

Pasted 154

Pasted 155

Pasted 156

 

Cache Groups (separate cache for cell phones)

The role of Cache Groups is to set up a separate cache for cell phones, enable the tables (desktop) and phones (mobile) user groups as shown, select the corresponding themes used by tables and phones, if you are just using a theme (responsive), just select the same. Other settings remain default.

Many optimization features rely on separate caching on cell phones, for example, the Perfmatters plugin control code is only enabled on cell phones and requires the site to enable separate caching on cell phones before it can take effect.

tablets(desktop)↓

Pasted 51

phones(mobile)↓

Pasted 52

For more details see.https://wordpress.org/support/topic/set-up-the-caching-separately-for-mobile-and-desktop/.

 

CDN Settings

If you are not using a CDN don't set it up here. If there is a plugin like Perfmatters installed, it is better to use the CDN function of Perfmatters.

Enter the accelerated domain name and save.

Pasted 39

You can click "Test Mirror" to test it, and it will show "Test passed" to indicate success.

Pasted 40

Check the foreground display is normal, view the source code found that the resource URL has become a cdn accelerated domain name.

Pasted 41

Other settings are left as default.

 

User Experience

Here set the image and Google Maps delayed loading content, if the corresponding function is not enabled ignore no need to set. If you have enabled delayed loading, just set it according to the picture.

Pasted 158

 

Extension

Here are some extensions, if the Pro version is enabled by default Fragment Cache. if you use Yoast plugin, install Yoast SEO extension. If you use Cloudflare CDN, install the CloudFlare extension.

The Image Service extension can generate WebP photos, but we have tested it on several sites and found that the conversion is not successful, it keeps indicating that the conversion is in progress, so it is not recommended to enable it. To optimize photos, please checkThe Ultimate WordPress Image Compression Optimization Tutorial.

 

Cautions

Exclude specific pages from being cached

The backend login address, personal center, shopping cart and other pages should not be cached and need to be excluded. In Page Cache > Advanced Settings, Never cache the following pages: Fill in the URL of the page that needs to be excluded from caching.

Pasted 115

 

Bypassing dynamic content caching

If you have problems such as not logged in status after login, user avatar and some visible contents after login are not displayed, sidebar is not displayed, etc., follow the below methods to set them. Method fromW3TC Support ForumGo to the Browser cache settings page.

Pasted 30

Top General↓ The following 3 items are unchecked.

Pasted 31

HTML & XML↓ Do not check the following 3 items.

Note: The Set cache control header below is sometimes automatically enabled after modifying other WT3C settings or upgrading the plugin, causing some dynamic content to be cached. To bypass dynamic content caching, check this item every time you upgrade the W3TC plugin or modify the configuration to keep it disabled.

Pasted 74

If the PHP cache cannot be bypassed even after the required settings, enter the page cachePasted 102Settings, check whether the following 2 items can be checked (enabled). If they can be checked, check all of them and try to enable them.

Pasted 103

 

W3TC Frequently Asked Questions

1- Modify after installing W3TCfunctions.phpIf a file such as this prompts the following problem, just temporarily turn off the Fragment Cache feature. The best way to add code is to use theCode SnippetsPlug-in, safe and stable and efficient.

Pasted 112

W3TC > General Settings and close the Fragment Cache as shown below.

Pasted 113

 

2- At first I was able to bypass PHP cache and log in normally to show some content, and then after some time the login was invalidated by cache. I found that if you change the settings of database cache, object cache, etc., especially changing the cache method will cause the red box of Broswer Cache setting below to be checked automatically. Go check it and if it is checked, uncheck it to save the settings and clear the cache.

Pasted 114

If it still does not work, the Page Cache settings inside the Late initialization, Late caching were opened to try.

 

3- Frontend prompt mysqli_num_fields() expects parameter 1 to be mysqli_result, bool given in /www/wwwroot/xxx.com/wp-includes/class-wpdb.php on line 3574

It is the W3TC database cache (Database Cache) to cause this problem, turn off the database cache to use the object cache (Object Cache).

 

Other more settings viewDetailed W3 Total Cache setup tutorialThis tutorial is a bit old, but written in great detail. Some of the options may be out of date look at the settings, for example, the tutorial page cache detailed settings inside an option is "Cache front page" (recommended to check), but in the new version of this option becomes "Don't cache front page" (not recommended to check), meaning the exact opposite.

For more settings and questions, please seeOfficial Documents, ,Official Support Forum.

 

4- After using W3TC the speed becomes much slower. The situation may vary a lot from service to service, maybe some servers are not configured properly, have many limitations or bugs (e.g. MariaDB 10.7.3 database in Pagoda Panel is unstable).). So after using this plugin it may be slow due to some errors.

If the speed becomes slower, try one by one: 1- change the caching mode of page cache to Disk: Basic; 2- change the caching mode of database cache and object cache one by one, or close them; remember to clean up the cache after modification to check the latest effect.

End

Article out of date? Have a better opinion? Have a question? Please leave your comments below and we will follow up.

Recommended Articles.
Comments :

发表评论

The email address will not be disclosed, and the URL needs to be removed from https://前缀 for insertion.

Chat
  • WeChat Service
Quick login without registration

Enter your username and password to log in

Have no account? Forgot password?