Using WP Rocket with Cloudflare

In this Article

Getting Started

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

WP Rocket is totally compatible and complementary with Cloudflare.

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

  1. Log in to your Cloudflare account
  2. Click the profile icon at the top right, then click My Profile
  3. Click API Tokens

  4. There you will find the Global API Key:

  5. After entering your Cloudflare password, the API key will be revealed. Copy the Global API key and paste into the WP Rocket settings. 

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):

define('WP_ROCKET_CF_API_KEY', 'put-your-API-key-here');

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 );

Account Email

Fill in the email address used on your Cloudflare account.

Zone ID

Enter your zone ID for your domain. This is found on the Overview page for your domain in your Cloudflare account: 

Development mode

This toggles Cloudflare’s development mode on or off.  Development Mode allows you to temporarily suspend Cloudflare’s edge caching and minification features. 

Did you know? Activating Development mode can be particularly useful when you are making changes to cacheable content (like images, CSS, or JavaScript), and you would like to see those changes right away.

Optimal settings

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

Relative protocol

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 http:// or https://).

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

See this guide if you are using Cloudflare's Cache Everything feature


The most common cause of issues when using Cloudflare is their  Rocket Loader feature. If you see display issues, or JavaScript errors while running Cloudflare, disable Rocket Loader and clear your cache to see if this fixes the problem. (Rocket Loader is in no way related to WP Rocket.)

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.