Using Cloudflare with WP Rocket
WP Rocket is compatible and complementary with Cloudflare. You can find more information and instructions on how to synchronize WP Rocket with Cloudflare, and other useful information below.
In this Article
Cloudflare ≠ CDN: Do not enter Cloudflare CNAMES on the CDN tab, this will break your site!
You may use a standard pull CDN in addition to Cloudflare depending on your needs. WP Rocket has its own premium CDN service, RocketCDN, and is also compatible with most CDN providers, including Amazon Cloudfront, Bunny CDN, KeyCDN and others. If you need information about how to use WP Rocket with a CDN, please: Using WP Rocket with a CDN
Using our Cloudflare add-on is not a requirement in most cases, it's only a convenience. Once you've set up your Cloudflare account correctly, it will be active for your site regardless of whether you are using the WP Rocket add-on. The add-on simply provides a convenient way to configure some settings.
However, if you are using Cloudflare's Cache Everything feature, then configuring our add-on will be required to sync the cache purging.
The first step to use them together, is adding your site to your Cloudflare account. If you haven't done this yet, follow Cloudflare's tutorial: Create a Cloudflare account and add a website. Then Change your domain name servers to Cloudflare.
Cloudflare can perform the minification process of CSS and JS files as well as WP Rocket, but WP Rocket also has the option to combine files which Cloudflare doesn't.
We recommend you activate minification in Cloudflare as well as WP Rocket to get the best results.
Note: If you use the WP Rocket Cloudflare add-on, you no longer need the official Cloudflare plugin (unless you use Cloudflare APO). WP Rocket provides the same functionality of providing originating IP addresses.
WP Rocket’s Cloudflare add-on
You must have direct access to your own Cloudflare account to get the API key information needed to configure the add-on. If you are using Cloudflare through an integration provided by your host, you may not be able to get this information and therefore you won't be able to use the add-on, but Cloudflare will still be active on your site.
In the Add-ons settings tab you will see the Cloudflare add-on. Switch Add-on status to ON:
Then click the Modify Options button. It will take you to the Cloudflare tab that has appeared under the Add-ons tab:
These are the settings you need to set:
Global API key
How to find your Global API key:
- Log in to your Cloudflare account
- Click the profile icon at the top right, then click My Profile
- Click API Tokens
- There you will find the Global API Key:
- After entering your Cloudflare password, the API key will be revealed. Copy the Global API key and paste into the WP Rocket settings.
Note: the Cloudflare Add-on works only with the Global API key, other Cloudflare API tokens are not supported.
Define API key in wp-config.php
If it suits your use case, you can also define your API key in your wp-config.php file. This can be useful if you have several sites under the same Cloudflare account. Here is how you would add it to your wp-config.php file (remember to replace the second value in the example with your own API key):
With the following line of code in wp-config.php you can also hide the API key field in WP Rocket’s settings if you prefer to keep it secret:
define( 'WP_ROCKET_CF_API_KEY_HIDDEN', true );
Fill in the email address used on your Cloudflare account.
Enter your zone ID for your domain. This is found on the Overview page for your domain in your Cloudflare account:
Cloudflare Add-on and Cloudflare APO
From WP Rocket 3.14, if you're using Cloudflare APO and the Cloudflare plugin is enabled and authenticated, the Cloudflare Add-on will be dimmed, and will have different information as shown below:
These are the texts inside the Cloudflare Add-on when APO is used:
Your site is using the official Cloudflare plugin. We have enabled Cloudflare auto-purge for compatibility. If you have APO activated, it is also compatible.
Cloudflare cache will be purged each time WP Rocket clears its cache to ensure content is always up-to-date.
In this case, you can manage Cloudflare settings directly from the Cloudflare plugin. WP Rocket will respect those settings.
You can find more information in the Using Cloudflare APO with WP Rocket article.
This toggles Cloudflare’s development mode on or off. Development Mode allows you to temporarily suspend Cloudflare’s edge caching and minification features.
Activating this option is highly recommended. WP Rocket automatically selects a pre-defined set of options for Cloudflare to improve the performance of your site:
- Set Cloudflare’s caching level to Standard
- Activate Cloudflare’s minification
- Deactivate Rocket Loader (name unrelated to WP Rocket)
- Set Cloudflare’s browser cache to 1 year
Heads up! This setting should only be activated if you use Cloudflare’s Flexible SSL feature.
You should NOT activate it when your WordPress site runs on full SSL!
The Relative protocol setting rewrites the URLs of static files (CSS, JS, images) to use a relative protocol (
// instead of
When should I Clear all Cloudflare cache files?
By default, it’s not necessary to press this button every time you clear WP Rocket’s cache.
It will clear the Cloudflare cache, and it mostly needed for troubleshooting, in case you've made changes to your files without changing their filenames, or when you think Cloudflare is serving outdated files for whatever reason.
If you have enabled Cache Everything, the Cloudflare cache will be purged automatically at the same time as the WP Rocket cache.
From the version 3.14, WP Rocket is compatible with Cloudflare APO, cache clearing will be synchronized if the Cloudflare plugin is enabled and authenticated. Please see more information in the Using Cloudflare APO with WP Rocket article.
Cloudways' Cloudflare Enterprise Plan
If you subscribe to Cloudflare Enterprise plan within your Cloudways hosting plan, WP Rocket won't be able to synchronize its cache with Cloudflare's in this case because Cloudways does not provide you with an API key and zone ID you can add to configure our Cloudflare add-on.
You'll need to purge the Cloudflare cache yourself each time you change the WP Rocket settings, or disable WP Rocket's page caching to keep only the optimizations. See: Disable page caching
- Rocket Loader
502 error or blank page when clearing the cacheIn some cases, when the Query Monitor plugin is active and Cloudflare is running on a site, clearing the cache can trigger a 502 error or a blank page error. If you find this issue on your site, you should disable the Query Monitor plugin. In general, the Query Monitor plugin should be enabled only while queries are being actively monitored.