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 bypassedW3 Total Cache Pro is a powerful caching plugin for W3, which has the functions of object caching, database caching, page fragment caching, shrinking/delaying the loading of CSS, JS and so on, which greatly reduces the burden on the server and shortens the loading speed of the page. It is a really useful caching plugin, this site uses W3 Total Cache Pro (Download) acceleration.

Once this site started usingWp RocketAccelerate, maybe I have a problem with the server configuration, html's browser cache off does not take effect resulting in visitors logging in and still displaying an unlogged in status (avatars and other content is not displayed). Finally, I usedW3 Total Cache ProPerfectly solves the problem because it uses the file below to configure the browser cache.

image 67

image 45

Because there are too many setting options, many people do not understand the settings lead to the effect can not be played, so it is not as famous as Wp Rocket, Fastest Cache. in fact, if you use it well than Wp Rocket better results! Write this W3 Total Cache setup tutorial is to let the white man can also make their own site settings.

Suggested PairingPerfmatters Asset Cleanup PluginThe Wp Rocket can be used in conjunction with the Wp Rocket and the Wp Rocket can be used in conjunction with the Wp Rocket and the Wp Rocket.

Note: If you are using VPS hosting (non-shared hosting) + Nginx system, it is recommended to restart Nginx after changing the W3 Total Cache settings to take effect.

 

W3 Total Cache setup tutorial

If you are prompted with the following message at the top after setting the settings, you need to restart Nginx for the settings to take effect.

image 97

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.

Page Fragment Cache - Page fragment caching is an advanced feature of page caching, which is available in the free version. Usually, if a page contains dynamic content, you need to set the whole page not to be cached (by default, it is not possible to cache only certain content) to ensure that the dynamic content is displayed normally, but the speed will be very slow.

The best practice is that the static content of the page is cached and prioritized for loading, and the dynamic content is cached and loaded separately, so that the fastest speed is guaranteed while the dynamic content is displayed normally. The role of page fragment caching is to achieve this purpose, by adding notes to select the dynamic content area to load dynamically, the other did not note the area is static cache, priority loading.

Page snippet caching is very, very suitable for e-commerce sites and sites with purchased/only member-visible content, which helps a lot to improve speed. However, it is not very useful for foreign trade sites or blog sites, so it is not recommended to enable this feature for foreign trade and blog sites.

Page Fragment Cache (Fragment Cache) is used by editing PHP templates and adding 1 code tag above and below the dynamic content code that is to bypass the cache, so it has a limited scope of use and conditions, and a high threshold for use. ClickSee details on how to use the clip cache.

Note: Enabling page fragment caching may cause editing of theme functions.php and other files to be unsaved, so you need to temporarily disable fragment caching to edit them. Alternatively, you can use theCode Snippetsetc. plugins to insert code instead of functions.php.

Tips: To use page fragment caching, the page caching method cannot be "Disk: Enhanced", only "Disk: Basic" or memory-based.If you want to use plugin functions or WordPress functions, you must set the page cache settings in theEnable delayed initialization.

Tips: Page fragment caching and fragment caching are completely different things, with different methods of enabling and controlling them. However, their role is the same, are to realize the cache page static content at the same time, separate, correctly load the dynamic content, the 2 together with the best results.

Fragment Cache - Fragment caching needs to be enabled in "Extension" in the following picture before it will appear in "General Settings". Fragment caching is to cache some dynamic data or result, it can be database query or board html content.

A fragment cache can be simply understood as an object cache, and the main difference between the two is that the contents of the cache are not the same. Fragment caching is mainly used to store simple data that expires in a short period of time, while object caching is used to store complex or large long-lasting data. By using both fragment caching and object caching, you can achieve more fine-grained cache control and improve website performance and user experience.

image 39    image 40

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.

Summarize: generally only recommended to use the object cache, it is a collection of data, an object may contain several database data, can largely replace the database cache. Object caching is html page caching supplement to catch leaks (some dynamic requests that are not cached).

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.

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 and has the worst performance.

Disk: Enhanced - This method loads cached pages from Apache or Nginx, so it is faster than Disk and is recommended. If the site slows down, choose the "Disk: Basic" method instead.

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

Memcached Cache - Storing cache files in memory is faster than disk (Dick) cache caching in the vast majority of 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 Wizard to test the settings suitable for your website, click "Installation 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, slow speed, change the settings, or disable the database cache and object cache function.

image 68

Just click "Next" ↓.

image 94

 

Tap "Test Page Cache"↓

image 91

Select the one with the shortest time. Tap the "Next" button for the next test. AllAfter setting if the site access speed becomes slow, page cache to change the option to try. We have a site using "Disk: Enhanced" speed is very slow, change to "Disk: Basic" speed back to normal.

image 92

 

Click the "Database Cache Button" ↓, regardless of the results of the speed test, directly select "None", how to click the "Next" button.

Here is an explanation: the database caching feature is not very compatible and can cause problems, so it is turned off by default. The following object caching feature works much better and can be used in its place: MySQL 8.0 removes the database caching feature because it is slower in some cases.

image 93

 

Point "test object cache" button ↓, select the shortest time, click "Next". If you test out the fastest "None", test again, in most cases you should choose "Redis" or "Memcached", these 2 fast generation of The size of the cache file is also much smaller.

Tips: To use Pagoda Panel, you need to install "Redis" and "Memcached" extensions in PHP settings.

image 95

 

Click the "Test Browser Cache" button ↓, regardless of the results, directly select "Enabled", how to click the "Next" button.

image 96

 

Image OptimizationWe recommend not to enable it, it is not very functional or effective, just click the "Next" button. We recommend disabling it and usingShortPixelorEwwwImage compression plugins such as this one work and experience better.

image 65

 

Delayed loadingNot recommended for activation.Click the "Next" button directly.Many people in W3TC forums have posted that the image display is abnormal after enabling it, so it is recommended to use thePerfmatterss image delayed loading feature instead (works best).

image 66

 

General settings

For the Pro version, it is recommended to go to the "Extensions" section to enable the desired features.

image 118

It is recommended to install Fragment Cache if it is Pro version; install Yoast SEO extension if using Yoast plugin; install CloudFlare extension if using Cloudflare CDN.

WebP Converter is not recommended to be enabled as it doesn't work very well and doesn't support converting to Avif format. Suggest checking out the one written by DiamoThe Ultimate WordPress Image Compression Optimization Tutorial, choose the right image compression solution.

After setup, you need to restart Nginx settings to take effect if it's VPS hosting (including managed), and you don't need to restart it if it's shared hosting.

 

acceptClick on the image below "General settings" to start setting up the rest of the plugin.

image 98

page cacheThe caching method is already enabled and selected in the setup wizard, so there is no need to set it up additionally, just leave it as default.

image 76

 

compressedMinify 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.

image 75

 

Opcode Cache)Set ↓ as shown.

image 70

 

Database Cache, ,object cache, ,browser cache In the "Installation Guide" setup wizard above, you have already set it, so just skip it here and ignore it. If you don't want to enable database caching in the future, remember to go back here to enable database caching instead, and select Memcached for the Method.

Below is my website setup, which I use separately for server reasonsObject Cache Pro pluginImplement object caching, so these 2 features are not enabled here ↓.

image 71

image 72

In any case, the browser cache below should be enabled.

image 73

 

Purge via WP Cron It is to set a timed task to clear all caches automatically, which can be understood as setting a cache expiration date and re-clearing it automatically when it expires.

image 74

 

Canadian dollar It is the CDN rewrite URL function.The role is to change the page's CSS/JS/images and other conventional URLs to CDN URLs, so that the corresponding resources can be loaded from the CDN.Wp Rocket, Perfmatters and other plug-ins have CDN rewrite URLs function. Only need to enable this function in a plug-in on the line, do not enable in multiple plug-ins, there will be conflicts.

If you want to use it, check the "Enable" box first, and select the type of the red box in the picture below as needed.If you use the domestic Tencent Cloud, Seven Bulls Cloud and other CDN select "Generic Mirror (Generic Mirror)" ↓.

image 78

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.

 

reverse proxy Sits between the web server and WordPress and can be used to perform various logic-based operations on incoming requests. If you don't know what it means keep it default, the vast majority of sites don't use it.

image 80

 

message library A message library that allows policy management to be shared between dynamic pools of servers. For example, each server in the pool uses opcode caching (not a shared resource) and clearing, which is then synchronized in real time between any number of servers; thus, each server behaves the same way even if the resource is not shared.

Just ignore if you can't read it, it's useless for 99.99%.

image 81

 

User Experience There are more settings, Adamo.Recommended usePerfmattersThe plugin has the same functionality instead of all the features shown below, and is much more powerful.It works better. If you don't want to usePerfmattersPlug-ins, on-demandJust enable the function shown below.

image 82

 

statisticians It is recommended to disable this feature. When enabled, an additional "Statistics" section will be created. image 84, you can view the data in the chart below, which Diamo does not find meaningful. Enabling it will slow down the front-end access speed, it is recommended to disable it.

image 83

 

fragment caching You need to enable it in "Extensions" before it appears in "General Settings".Fragment caching is very, very good for e-commerce sites and sites with purchased/members-only content, and it helps a lot with speed. If you want to enable it, choose "In-Memory Cache" or Memcached or Redis, and test it yourself.

image 90

 

sundry It is recommended to keep it as default, it is not used by the majority of websites and has no particular significance.

image 85

 

adjust components during testingIt is recommended to keep it closed.Interested and curious you can enable it and see, remember to turn it off after only a short time.

image 86

 

WebP ConverterIt's the Picture to WebP function, which I don't think works well for Mo, and the results are average. Suggest to disable it.use (sth. different)ShortPixelorEwwwImage compression plugins such as this one work and experience better.

image 87

 

Google Page SpeedNeed to link Google account to use on websiteGoogle Speed Test. Suggested to disable, direct accessGoogle Speed TestThe official speed test is better.

image 88

 

Import/ExportThe setup is well understood and not much explained.

image 89

General settingsTo conclude, here are the detailed settings for each feature.

 

Page Cache Settings

image 99

The "No page caching for logged in users" and "No page caching for the following user groups" are two features that need to be addressed specifically. If you want all logged in users to bypass (not show) the cache, just enable "Logged in users don't cache pages".

If you want some logged in roles to bypass (not show) the cache and other logged in roles to show the cache, disable "Logged in users don't cache pages" and then enable "The following user groups don't cache pages" and check the roles that you want to bypass (not show) the cache. Then enable "The following user groups do not cache pages" and check the roles that you want to bypass (not show) the cache.

 

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 up according to the following chart

image 47

image 48

CSS & JS settings follow the chart below.

image 49

image 50

 

HTML & XML settings in accordance with the following chart, if you site membership features, after logging in will display different dynamic content (such as the site's upper-right corner avatar and so on), the following red box is set to 2 seconds. This will not show the cached content after login. You need to use it together with the "logged-in users don't cache pages" function in the page caching settings.

image 51

 

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

image 52

image 53

 

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

image 54

image 55

Otherwise keep the defaults.

 

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

 

Cautions

Exclude pages from being cached

Backend login address, personal center, shopping cart and other pages should not be cached and need to be excluded. In the "Page Cache" section > "Advanced" settings, fill in the "Never cache the following pages:" field to exclude the cached page URLs.

image 116

To exclude all pages from being cached based on cookies, enter cookies in the "Advanced" settings in the location shown below.

image 117

 

How to use page fragment caching

Newbies should not use this method, easy to get problems. Some page builder to build the content can not add notes, can not use this method.

1): First of all, you need to add the following code in the wp-config.php file in the root directory of the website to enable the note function, somesecurestring can be customized, for example, we changed to diiamodynacache.

define('W3TC_DYNAMIC_SECURITY', 'somesecurestring').

Then edit the corresponding file php template and add notes before and after the dynamic content , that's it. There are five ways to use this note.

Example 1.

Example 2.
any PHP code
Example 3.

echo rand();

Example 4.

Example 5.
path/to/file.php

 

(2): In the "Compression" section, the following exclusion box, enter mclude and mfunc, one line at a time.

image 110

 

(3): In the "General Settings" section, the following picture Page caching method can not be selected "Disk: Enhanced", but all other options can be selected.

image 112

If you use WordPress functions and hooks for dynamic content, you need to enable the "Delayed Initialization" feature shown below in the "General Settings" section. The reason why the figure below is not enabled is because my "page caching method" is "Disk: Enhanced", change the selection of other can enable the function.

image 113

 

Dynamic Content Cache Display Failed to be Cached

This issue does not exist if the page fragment caching and fragment caching features are used successfully. Usually when you use the full page caching feature, the content is loaded using Ajax or something like that, and the page cache is cached by the browser, so the dynamic content is not updated successfully.

In the "Browser Cache" settings section, dynamic content should be displayed normally according to the settings we suggested above. If it appears that after login, it displays the status of not logged in, the user's avatar and some contents visible after login are not displayed, the sidebar is not displayed, and you need to refresh the page before it is displayed. Follow the below method to set it up. Methods fromW3TC Support ForumGo to the Browser cache settings page.

Pasted 30

Top "General Settings" ↓, the following two items do not check enable.

image 114

HTML & XML ↓ Just follow the instructions below to set it up.

image 63

After setup, you need to restart Nginx settings to take effect if it's VPS hosting (including managed), and you don't need to restart it if it's shared hosting.

 

Use with object caches such as Object cache pro

Officially, it can be used with Object cache plugins such as Object cache pro, with a different division of labor and no impact.

image 115

 

Summary of all WP Cron task settings and features for W3TC

The image below summarizes where the plugin can enable/set WP Cron tasks and what the corresponding WP Cron does. At a glance, set it up as needed.

image 101

 

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 Snippets and other plug-ins that are secure, stable and efficient.

Pasted 112

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

Pasted 113

 

2- 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).

 

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.

Try them one by one if they slow down:

1) Page Cache changed caching method to Disk: Basic;

2) Database cache and object cache to change the cache mode one by one, if there is no effect on one by one to close the 2 functions to see;

Remember to clear your cache after modifying to see the latest results.

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.

 

4- Elementor editing page has been turning in circles, only individual simple pages can be opened, complex pages can not be opened. f12 view many resources prompt letter 503 can not be loaded. Is a plug-in conflict, disable the following function, if it is a VPS host need to restart Nginx, refresh to return to normal.

image 59

image 60

image 61

If the following functions are enabled, check the red box

image 62

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

Comments :

发表评论

The email address will be invisible, To put URL pls remove "https://" and "www".

Chat
  • WeChat customer service
Quick login without registration

Enter your username and password to log in

Have no account? Forgot password?