WordPress Cache Enabler Plugin

The WordPress Cache Enabler plugin is a lightweight caching plugin that creates static HTML files and stores them on your web server. This means that a static HTML file will be delivered whenever possible to provide users with the response data that would otherwise involve the resource intensive process of using the WP core, plugins, and database. This simple, yet powerful plugin is easy to use, needs minimal configuration and best of all helps improve site load time.

Installation

Installation of the WordPress Cache Enabler plugin is easily and can be done in just a few steps. Watch our installation video or follow the outlined steps below.

WordPress Cache Enabler Plugin Settings

Caching in WordPress is an important factor to improve the overall web performance of your website. This video shows you how to configure the WordPress Cache Enabler plugin.

  1. Navigate to the Plugins page in your WordPress Dashboard and select Add New.
  2. Search for “Cache Enabler – WordPress Caching” and select Install Now > Activate Plugin.
  3. The plugin is now installed and activated on your WordPress installation and you can navigate to the plugin’s settings by going to Settings > Cache Enablercache-enabler

Features

The WordPress Cache Enabler Plugin comes with the following features and customization options.

  • Fast disk cache engine
  • Manually clear cache from the admin bar or plugin settings page
  • Manually purge page-specific cache
  • Automated cache expiry
  • Option to enable automatic clearing of cache if a new comment is posted
  • Cache size displayed in your WordPress dashboard
  • Option to enable cache minification (HTML or HTML & inline JS)
  • WordPress multisite support
  • Custom Post Type support
  • Option to exclude caching of specific posts or pages by ID
  • Integration of WebP images
  • HTTP/2 focused
  • Works perfectly with Autoptimize
  • Supports responsive images via srcset in WordPress 4.4

The WordPress Cache Enabler also makes use of the If Modified Since header to help the browser determine whether the content has changed since the creation of the static cached file. If the content has not changed, the status code for the initial HTML document will be returned to the browser as 304. If the content has changed, the HTML document is fetched again, returning a status code of 200.wordpress-cache-304-not-modified

FAQ

How can I check if the cache enabler is working on my site?

You can quickly verify that the Cache Enabler is delivering a cached version of a specific page by logging out of your WordPress installation and checking the page source for either of these comments:

<!-- Cache Enabler by KeyCDN @ 10.11.2015 17:32:29 (webp gzip) -->
<!-- Cache Enabler by KeyCDN @ 10.11.2015 17:32:29 (webp) -->
<!-- Cache Enabler by KeyCDN @ 10.11.2015 17:32:29 (html gzip) -->
<!-- Cache Enabler by KeyCDN @ 10.11.2015 17:32:29 (html) -->

Upon activation, Cache Enabler performs 2 things:

  1. Adds define('WP_CACHE', true); // Added by Cache Enabler to your wp-config.php file
  2. Copies the advanced-cache.php file from the cache-enabler to the wp-content directory

The X-Cache-Handler: wp header is shown if the advanced-cache.php file is used. Otherwise, if WP_CACHE is set to false (e.g. define('WP_CACHE', false);) then Cache Enabler will not bypass PHP and you will see the following header X-Cache-Handler: php.

cache enabler x cache handler header

If upon activation Cache Enabler is unable to write to your wp-config.php file, then you will receive the following warning in your WordPress dashboard.

cache enabler warning

If you receive this warning, you can either change your file permissions and reinstall the plugin or manually add define('WP_CACHE', true); to your wp-config.php file. This will greatly help improve the performance of your website.

How can I convert my images to WebP?

To convert images to Webp, use the Cache Enabler plugin in conjunction with the Optimus Image Optimizer Plugin and enable the Webp options on both plugins.

How does the WebP integration work?

The WordPress Cache Enabler parses the jpeg and png images located in your upload directory to see if there is an equivalent WebP image (generated by Optimus). These WebP images are then included in the WebP cached html file.

Does Cache Enabler work with Disqus conditional load plugin?

Yes. In order to have Cache Enabler work properly with DCL plugin, simply navigate to DCL settings and set the Caching Support option to “Enable”. Save your settings and DCL will now work properly with Cache Enabler.

dcl settings

Does Cache Enabler work with mobile themes if the desktop and mobile versions are different?

It is not recommended to use the Cache Enabler plugin if a mobile theme or plugin is used that shows different layouts for desktop and mobile. The cache is bypassed if any of these plugins are used:

  • WPtouch
  • Carrington
  • Jetpack
  • Handheld

Otherwise the cached version is delivered to the mobile user.

Why isn’t my Woocommerce stock updating?

If you are experiencing an issue with Woocommerce stock being cached and therefore not updating, try updating to the latest version of Woocommerce. As of version 2.5.2 the issue is resolved and the stock number no longer conflicts with caching plugins.

What happens if a new post is published?

By default, only the home page cache is cleared when a new post is published. However, In the settings page of Cache Enabler you have the option to clear the complete cache when a new post is published.

cache-enabler-cache-behavior

How often is the cache updated?

There are a few options you can set that determine how often the cache is updated.

  1. You have the option to enable the clearing of complete cache every time someone posts a new comment. This can be done from the Cache Enabler settings page.
  2. You can clear the cache manually from the WordPress admin bar or by selecting the Save Changes button from the Cache Enabler settings page.cache-enabler-clear-cache
  3. You have the option to clear the complete cache or page specific cache each time a post is updated. This can be achieved directly from the post page.clear-cache-from-post
  4. The cache can also be cleared automatically in predetermined time intervals. This can be defined directly in the WordPress Cache Enabler’s settings page under the Cache Expiry option. Set how often the cache should be cleared (in hours). A Cache Expiry of 0 means the cache never expires automatically.

Can I clear the cache of a specific URL?

Yes. You can clear the cache of a specific URL directly from the WordPress admin bar by clicking “Clear URL Cache”.

cache enabler clear url cache

Does Cache Enabler work with default permalinks?

No. Cache Enabler does not work with default permalinks

Can I use Cache Enabler with the WordPress Nexus theme?

Yes. However, upon installing the WordPress Cache Enabler on a site using the Nexus theme, you must rebuild the permalinks. This can be done by going to your WordPress Dashboard > Settings > Permalinks and selecting Save Changes.

Will Cache Enabler’s expiry function still work if I’m using the advanced snippet?

No. Cache Enabler’s ability to automatically expire the cache based on a defined period will no longer work as the PHP calls required for that function will be bypassed.

wordpress cache enabler cache expiry

However, a cron job may be created in order to continue expiring the cache automatically. Add the following command to your cron job once you have determined the time period for which you would like the cache to expire */1 * * * * rm -rf /path/to/your/wordpress/wp-content/cache/cache-enabler/

How can I verify that the advanced snippet is bypassing PHP?

By adding the advanced configuration snippet to your Apache server you have the ability to bypass PHP in order to retrieve the static HTML file that was created by the WordPress Cache Enabler plugin. In order to ensure you are in fact bypassing PHP after you’ve added the snippet, open up your developer tools, navigate to Network and select the HTML file of your page.

If you’ve added the advanced snippet configuration below, upon checking the headers you will notice that no special WordPress Cache Enabler headers are added. If the X-Cache-Handler header is not present, then your advanced configuration snippet is properly implemented.

You can also check your response headers using a cURL command such as:

curl -D - http://wordpress.keycdn.net/ -o /dev/null
 % Total % Received % Xferd Average Speed Time Time Time Current
 Dload Upload Total Spent Left Speed
 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0HTTP/1.1 200 OK
Server: nginx
Date: Tue, 17 May 2016 11:59:04 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: PHP/5.5.9-1ubuntu4.14

How do I find a page or post ID?

You can easily find your page or post IDs for adding to the cache exclusions list in the settings page. To find the ID, you can hover over a page or post title from the main list page and see the page or post idea at the bottom left of the page like so:

Page-ID-Hover

Alternatively, you may click into a specific page or post and the ID will appear in the url:

Page-ID-URL

How do I use Cache Enabler on a WordPress multisite setup?

Using the WordPress Cache Enabler plugin on a multisite setup is quite straightforward. Once the plugin is downloaded you have two options:

  1. You can activate Cache Enabler via network activation and it will start working for each site.
  2. You can enable Cache Enabler on each site individually if you don’t want it enabled across the entire network.

All the cache and settings are configured to work individually for each site. Therefore, you can clear the cache on site 1, while site 2 and 3 will retain their cache. If you need to access the cached files from the backend, they are located at /wp-content/cache/cache-enabler/yourdomain.com.

Advanced Configuration

A more advanced configuration can be implemented on the origin web server to bypass PHP entirely for even faster delivery. The following configuration snippets can be implemented on Apache or Nginx servers. The advanced configuration snippets should only be used by those who are experienced in modifying .htaccess files. Furthermore, the default Cache Enabler setup should satisfy the majority of use-cases.

This configuration is optional and is not necessary to implement in order to use the Cache Enabler plugin. It is only a suggested configuration for those who want to entirely bypass PHP if a static HTML file exists. The Expiry directive will be bypassed as well with the advanced configuration.

Apache

Add the following snippet before the # BEGIN WordPress section in your .htaccess file if you are using Apache 2.3.9 or later.

The snippet defines certain conditions and if they are met then the RewriteRule will be triggered. For the gzip version, the last condition, RewriteCond %{DOCUMENT_ROOT}%{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index.html.gz -f, checks to see if the HTML static file is available and if that condition, and all other conditions are met, a rewrite is triggered. The static HTML file is then directly fetched (preventing any PHP calls) and sent back to the client.

The SUB_PATH variable needs to be adjusted accordingly if you have installed WordPress in a sub directory (e.g. http://www.example.com/blog requires a change to
SUB_PATH=/blog/wp-content/cache/cache-enabler/).

Additionally, if you change the location of wp-admin, this must also be adjusted in the following condition RewriteCond %{ENV:CE_PATH} !^/wp-admin/.*.

# BEGIN Cache Enabler
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# set blog sub path
SetEnvIf Request_URI "^(.*)$" SUB_PATH=/wp-content/cache/cache-enabler/

# set Cache Enabler path
SetEnvIf Request_URI "^(.*)$" CE_PATH=$1
SetEnvIf Request_URI "^(/)index.php$" CE_PATH=$1

<IfModule mod_mime.c>
# webp HTML file
RewriteCond %{ENV:CE_PATH} /$
RewriteCond %{ENV:CE_PATH} !^/wp-admin/.*
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{HTTP:Accept} image/webp
RewriteCond %{DOCUMENT_ROOT}%{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index-webp.html.gz -f
RewriteRule ^(.*) %{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index-webp.html.gz [L]

# gzip HTML file
RewriteCond %{ENV:CE_PATH} /$
RewriteCond %{ENV:CE_PATH} !^/wp-admin/.*
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{DOCUMENT_ROOT}%{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index.html.gz -f
RewriteRule ^(.*) %{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index.html.gz [L]

AddType text/html .gz
AddEncoding gzip .gz
</IfModule>

# webp HTML file
RewriteCond %{ENV:CE_PATH} /$
RewriteCond %{ENV:CE_PATH} !^/wp-admin/.*
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
RewriteCond %{HTTP:Accept} image/webp
RewriteCond %{DOCUMENT_ROOT}%{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index-webp.html -f
RewriteRule ^(.*) %{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index-webp.html [L]

# default HTML file
RewriteCond %{ENV:CE_PATH} /$
RewriteCond %{ENV:CE_PATH} !^/wp-admin/.*
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
RewriteCond %{DOCUMENT_ROOT}%{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index.html -f
RewriteRule ^(.*) %{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index.html [L]

# wp override
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [END]
</IfModule>
# END Cache Enabler

We recommend to upgrade Apache whenever possible but you might need to use this snippet if you are using an older Apache release (< 2.3.9) or if you get an error with the example above:

# BEGIN Cache Enabler
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# set blog sub path
SetEnvIf Request_URI "^(.*)$" SUB_PATH=/wp-content/cache/cache-enabler/

# set Cache Enabler path
SetEnvIf Request_URI "^(.*)$" CE_PATH=$1

<IfModule mod_mime.c>
# webp HTML file
RewriteCond %{ENV:CE_PATH} /$
RewriteCond %{ENV:CE_PATH} !^/wp-admin/.*
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{HTTP:Accept} image/webp
RewriteCond %{DOCUMENT_ROOT}%{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index-webp.html.gz -f
RewriteRule ^(.*) %{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index-webp.html.gz [L]

# gzip HTML file
RewriteCond %{ENV:CE_PATH} /$
RewriteCond %{ENV:CE_PATH} !^/wp-admin/.*
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{DOCUMENT_ROOT}%{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index.html.gz -f
RewriteRule ^(.*) %{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index.html.gz [L]

AddType text/html .gz
AddEncoding gzip .gz
</IfModule>

# webp HTML file
RewriteCond %{ENV:CE_PATH} /$
RewriteCond %{ENV:CE_PATH} !^/wp-admin/.*
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
RewriteCond %{HTTP:Accept} image/webp
RewriteCond %{DOCUMENT_ROOT}%{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index-webp.html -f
RewriteRule ^(.*) %{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index-webp.html [L]

# default HTML file
RewriteCond %{ENV:CE_PATH} /$
RewriteCond %{ENV:CE_PATH} !^/wp-admin/.*
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
RewriteCond %{DOCUMENT_ROOT}%{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index.html -f
RewriteRule ^(.*) %{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index.html [L]
</IfModule>
# END Cache Enabler

Nginx

We recommend to use the gzip_static on; directive to directly deliver the gzipped version of the static HTML file to the client. However, gzip_static is not required but you should have at least gzip enabled gzip on; for best performance.

The $custom_subdir variable needs to be adjusted accordingly if you have installed WordPress in a sub directory (e.g. http://www.example.com/blog).

server {

    set $cache_uri $request_uri;

    # bypass cache if POST requests or URLs with a query string
    if ($request_method = POST) {
        set $cache_uri 'nullcache';
    }
    if ($query_string != "") {
        set $cache_uri 'nullcache';
    }

    # bypass cache if URLs containing the following strings
    if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
        set $cache_uri 'nullcache';
    }

    # bypass cache if the cookies containing the following strings
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
        set $cache_uri 'nullcache';
    }

    # custom sub directory e.g. /blog
    set $custom_subdir '';

    # default html file
    set $cache_enabler_uri '${custom_subdir}/wp-content/cache/cache-enabler/${http_host}${cache_uri}index.html';

    # webp html file
    if ($http_accept ~* "image/webp") {
        set $cache_enabler_uri '${custom_subdir}/wp-content/cache/cache-enabler/${http_host}${cache_uri}index-webp.html';
    }

    location / {
        gzip_static on; # this directive is not required but recommended
        try_files $cache_enabler_uri $uri $uri/ $custom_subdir/index.php?$args;
    }

    ...

}

Clearing Cache Via Third Party

The PHP snippet below can be used to clear the cache via a third party such as a Cron Job for example. The first section initializes the WordPress environment, normally this PHP file should be located in your WordPress root directory. The second if performs the action of completely clearing the cache and with the third if you have the ability to specify which post ID you would like to clear the cache for.

// initilize WordPress environment
if ( !defined('ABSPATH') ) {
	require_once('./wp-load.php');
}

if ( has_action('ce_clear_cache') ) {
    do_action('ce_clear_cache');
}

if ( has_action('ce_clear_post_cache') ) {
    do_action('ce_clear_post_cache', 1111); // post_id
}