WordPress is the most powerful blogging platform on earth (I don’t know if aliens use it :-p), I’m not going much further about WordPress because if you have reached this post it means that you have searched google for WordPress cache solution or something else related to WordPress and you already know what WordPress is.
What is cache and do you need it?
Based on Wikipedia: “In computing, a cache is a component that stores data so future requests for that data can be served faster…”
So it means that cache can help us make our website faster.
But how? There are different type of cache: like server cache, browser cache etc.
Server cache for example a user visits the homepage of a website, when the user types the url on the address bar and hits enter a request has been sent to the server where the website is hosted, the server executes the corresponding script, in WordPress index.php, during the script execution a query has been sent to the database server, for example to load 10 recent posts. This query now is cached on RAM for a period of time (based on configuration). When the next visitor will come to the homepage of the website the query to load 10 recent posts will not be executed anymore from the server but the query result will be served directly from the RAM so the page will load faster.
Browser cache logic is the same with server cache but in the case of browser cache the files are cached (stored) on the user computer and they are static files like images, js and css. In this case when the user visit the webpage the static files are stored on his computer and when he visit it again the browser checks only if these files are changed or not, if they are not changed then the browser servers them from users computer so the website is loaded much faster as there is no need to make requests to the server for those files.
The difference between server cache and browser cache is that for example in server cache a query stored in RAM will be served to all visitors instead of browser cache when cached files are served to each user from his own computer after the first time he visits the website.
It has happened to all of us: when we navigate to a website if it is not really very very important to us and if it doesn’t load in 5-10 sec we hit the back or stop button on our browser. So if you are a website owner; first thing you have to do is to check your website speed and load time, because if it take more then 5 seconds that you are losing a lot of visitors.
If your website is using WordPress than you can save a lot of time and money to speed your website as there are some nice plugins on WordPress plugin directory that can help you speed your site.
The most well known plugins used for WordPress cache are: W3 Total Cache, WP Super Cache and WP Rocket.
So far so good, but how will you choose which one to use for your website?
First thing that you have to do is to check your website page speed without a cache plugin and identify your website problems and needs, what is slowing it?
You can check page speed with: GTmetrix or Google Pagespeed. There are a lot of other tools around the internet but these two are the most popular.
What are we going to do is: Testing an example website without any WordPress Cache plugin enabled and then we will test each plugin separately and decide based on some criteria:
- Cost. Some of the plugins used for cache are free and some others with a paid subscription. But being a paid plugin doesn’t mean that it is better then those who are free.
- Easy to install and configure. We will test each the three plugins mentioned above and measure the time needed to configure each one.
- Functionality and compatibility. Not every cache plugin is compatible with your theme, server configuration, WordPress configuration or with other plugins you have installed on your website.
- Support, forum and documentation. Based on your website configuration and your server not everything will work as you expected, so some times you may need some support on what you will want to achieve.
Testing without WordPress Cache plugins
First we are going to test a website without any cache plugin and see the website performance and speed. After that we will test the same website with WordPress Cache enabled and test each plugin separately.
The website that we will use for test is: www.emilushi.com which uses the same WordPress version, theme, plugins and content from www.shomtek.com.
I’n the image below we may see the page-speed test of the webpage without any WordPress cache plugin enabled.
The server where the tests are made is a Dedicated Cloud Server with 2GB of Ram, 2 Cores with latest Apache Version, Nginx as Reverse Proxy Server and PHP 5.6.19. The server is using Free version of CloudFlare.
Below is the result of the AB test (Apache stress test)
ab -n 1000 -c 100 http://www.emilushi.com/
The test above will send 1000 request to www.emilushi.com with 100 concurrent requests. We haven’t specified the time for test as we want to know which will be the maximum number of requests made per second.
Concurrency Level: 100 Time taken for tests: 205.626 seconds Complete requests: 1000 Failed requests: 0 Requests per second: 4.86 [#/sec] (mean) Time per request: 20562.646 [ms] (mean) Time per request: 205.626 [ms] (mean, across all concurrent requests) Transfer rate: 6.59 [Kbytes/sec] received
Conclusion: Based on the tests made without any WordPress cache plugin enabled we have
- Page-speed score: 67
- YSlow score: 68
- Page Load Time: 5.3s (not bad)
- Requests per second:4.86
Now lets test the same website with cache plugins enabled and we will start with WP Super Cache.
WP Super Cache
WP Super Cache is a free WordPress plugin created and maintained by Automatic with more than 1 million active installs and rated 4.2 out of 5 on the WordPress plugin directory.
What WP Super Cache does is: after the first visit it creates an html file for each page. Then the webpage will be served as a static html file for all the other users that will visit the website.
If you install WP Super Cache you will have to visit each page of your website to create the static file of each page so when a visitor will want to access you website it will be served from the cached file.
We will do the same server load test that we did before when we had no WordPress Cache plugin enable and test the server load time with WP Super Cache enabled and configured.
The test result for:
ab -n 1000 -c 100 http://www.emilushi.com/
is as below:
Concurrency Level: 100 Time taken for tests: 174.149 seconds Complete requests: 1000 Requests per second: 5.74 [#/sec] (mean) Time per request: 17414.932 [ms] (mean) Time per request: 174.149 [ms] (mean, across all concurrent requests) Transfer rate: 470.97 [Kbytes/sec] received
As we can see from the result above we have saved 31.477s from the total time needed to take the test and the Requests per second is increased with 0.88 requests/s, it’s only a bit better that the website version without a WordPress Cache plugin.
Below you can watch a video that we have recorded testing the time needed for plugin installation, configuration and the page speed scored with cache enabled.
W3 Total Cache
What i really like from it is that W3 Total Cache supports opcode cache and memcached. So if you have a server configured to work with memcached your website will be much faster otherwise you will have to use disk cache which is a some how slower then using memcached.
We have taken the same Apache stress test that we did using WP Super Cache and the result is as above:
Concurrency Level: 100 Time taken for tests: 164.136 seconds Complete requests: 1000 Requests per second: 6.09 [#/sec] (mean) Time per request: 16413.563 [ms] (mean) Time per request: 164.136 [ms] (mean, across all concurrent requests) Transfer rate: 395.38 [Kbytes/sec] received
As we can see from the test result W3 Total Cache is better the WP Super Cache but the performance improvement is not that big. So we have saved only 10s from Total time needed to take the test and only few points from Requests per second.
Watch the view below that we have recorded to test time needed to install and configure W3 Total Cache and as well the test we did on GTmetrix.
WP RocketWP Rocket is a commercial plugin, so you will not find it on WordPress repository, instead you will have to buy a license from WP-Rocket.me and install the plugin manually.
Based on my experience WP Rocket is the most useful cache plugin that i have ever used on my website or on our clients websites.
Other features that are supported on WP Rocked are: LazyLoad for images and embed video, DNS prefetch, CloudFlare Compatibility, CDN, Varnish Caching Purge etc.
Another feature that will become available soon is the fragment cache. What fragment cache does is: it helps you cache all the page of a website instead of a dynamic part of it, so if you have a block of code that changes every page load or every specific time you will not want to cache that part as it will brake the function, so by using fragment cache you may cache or not specific blocks of code inside a single page.
At the moment if you will need to use fragment cache then you will have to use W3 Total Cache as it supports fragment caching.
Below you will find the Apache stress test we did with WP Rocket enabled.
Concurrency Level: 100 Time taken for tests: 125.145 seconds Complete requests: 1000 Requests per second: 7.99 [#/sec] (mean) Time per request: 12514.536 [ms] (mean) Time per request: 125.145 [ms] (mean, across all concurrent requests) Transfer rate: 445.18 [Kbytes/sec] received
As we can see from the test WP Rocket is much more faster then the other two plugins we have tested before. The total time needed for test 40s less the W3 Total Cache and as well the number of request per second is about 2 which mean that we may have 2 more requests per second compared to W3 Total Cache, about 2.5 requests more than WP Super Cache and about 3.5 requests more than we had with no WordPress Cache plugin enabled.
We have recorded a video as we did before with the other two plugins to test the time needed for the configuration and the pagespeed using GTmetrix. You can watch the video below.
Based on all the test we have made we may say that WP Rocket is faster then the other two plugins. If you will want to use a free plugin then you will have to try W3 Total Cache.
Remember that you can’t have same results on different servers and on different websites as the pagespeed and plugin configuration will be depended on your server configuration, other plugins that you are using on your website and as well on your WordPress theme as well.
In the chart below you may see all the important results for all the three plugins and decide which one to use.
Fixing WP Rocket “bug”
If you will have the same error that I had when configuring WP Rocket on the video above, than you will have to follow the below steps:
1. Navigate to WordPress plugin folder and then go to:
open minify.php, go to line 74 and replace this:
$base_url = WP_ROCKET_URL . 'min/?f=';
$base_url = WP_ROCKET_URL . 'min/index.php?f=';
2.Navigate to WordPress plugin folder and then go to:
open .htaccess file and replace all the content of file with this:
DirectoryIndex index.php <Files index.php> Order allow,deny Allow from all Require all granted </Files> <IfModule mod_rewrite.c> RewriteEngine on RewriteBase /min RewriteRule ^([bfg]=.*) index.php?$1 [L,NE] </IfModule> <IfModule mod_env.c> SetEnv no-gzip </IfModule>