Using Cloudflare APO with WP Rocket
WP Rocket is compatible with Cloudflare APO, meaning that the cache clearing between WP Rocket and Cloudflare APO will be synchronized.
Note: In order to work, this compatibility requires the Cloudflare's official plugin to be activated, and the Cloudflare account to be fully authenticated in that plugin.
When Cloudflare's official plugin is active, Cloudflare's Add-on will be dimmed, and cache clearing will be handled automatically.
If Cloudflare's official plugin is not installed or is not active, Cloudflare's Add-on can still be used to synchronize other Cloudflare features except for synchronizing cache clearing. This configuration is aimed at Cloudflare users that are not using APO, see more information here.
Cache clearing
Cache clearing between WP Rocket and Cloudflare APO will be synchronized as follows:
Full cache clearing
The APO cache for the whole site will be automatically cleared when WP Rocket's full cache clearing happens. The cache for JavaScript and CSS files will be cleared from Cloudflare's servers as well. As a reference please see scenarios when the whole cache is cleared.
In addition to the above scenarios, APO's cache will be cleared upon WP Rocket deactivation to reflect the WP Rocket status on APO's side.
Please note that Clearing APO cache with the “ Purge Everything” option within Cloudflare's official plugin will not clear WP Rocket cache.
Partial cache clearing
WP Rocket clears the cache for a few specific pages in these scenarios, with APO compatibility, those specific URLs (except for date archives and term archives) will be automatically cleared from Cloudflare network as well.
Using the Purge Individual Files option in Cloudflare's official plugin will not clear WP Rocket cache for the specific purged pages.
Notes:
- The automatic cache purging for Cloudflare APO Cache won't be triggered when Cache Lifespan runs the cache clearing for expired cache files.
- The cache clearing synchronization will also purge Cache Everything.
Using Cloudflare APO with Preload
WP Rocket's Preload cache option can cache files and work along with APO. However, there may be problems if the APO cache becomes unsynchronized. You can find more information here.
Additionally, pages that were preloaded by WP Rocket won't have the Cf-Edge-Cache
header. This header is added by the Cloudflare plugin using PHP, therefore, this won't work on pages that were cached by the Preload first. There are no reported issues caused by this behavior.
Using Cloudflare APO with Mobile Cache
In WP Rocket 3.16 and later, WP Rocket's Mobile Cache option automatically creates mobile-specific cache files. Therefore, in Cloudflare APO, you should make sure to enable their Caching by device type option.
Now, for WP Rocket versions older than 3.16, the Separate cache files for mobile devices feature and Cloudflare's Cache by device type should be configured accordingly to have the same behavior when delivering cache to different device types.
In any case, if there is a mismatch in the status of the features, the following admin notices will be displayed:
WP Rocket: You are using "Separate cache files for mobile devices". You need to activate "Cache by Device Type" setting on Cloudflare APO to serve the right version of the cache.
WP Rocket: You have "Cache by Device Type" enabled on Cloudflare APO. If you judge it necessary for the website to have a different cache on mobile and desktop, we suggest you enable our “Separate Cache Files for Mobiles Devices” to ensure the generated cache is accurate.
Cloudflare APO and query strings caching
Cloudflare APO is not compatible with the Cache Query String(s) feature.
With WP Rocket, pages using specific parameters will get the default caching, and URLs using other parameters can be cached using the Cache Query String(s) feature.
On the other hand, while Cloudflare APO can serve cache to URLs with some parameters too, it doesn't allow serving cache to URLs with custom parameters, more information can be found here.
Please note, if Cache Everything is used along with APO, any URL using query strings added to the Cache Query String(s) box will be cached as expected. If Cache Everything is not used, APO won't cache URLs with cached query strings.
Cloudflare APO and dynamic/mandatory cookies
Cloudflare APO is not compatible with WP Rocket's dynamic and mandatory cookies features, because APO can't serve different cache versions based on different cookie values.
Therefore, there will be problems with the cache version served to the visitors in the following cases:
- Plugins with compatibility based on mandatory cookies or with dynamic cookies are active.
- The WP Rocket | Cache Dynamic Cookie or WP Rocket | Cache Mandatory Cookie helper plugins are active.
- The
rocket_cache_dynamic_cookies
androcket_cache_mandatory_cookies
filters are used for other custom implementations.
In the above cases, the following admin notice will be displayed:
WP Rocket: You are using "Dynamic Cookies Cache". Cloudflare APO is not yet compatible with that feature.
You should either disable Cloudflare APO or check with the theme/plugin requiring the use of “Dynamic Cookies Cache” developers for an alternative way to be page-cache friendly.
Cloudflare APO and Never Cache Cookies
By default, APO bypasses the cache when a cookie with one of these prefixes is detected in the browser.
You can apply this same exclusion on WP Rocket's side, using the Never Cache Cookies feature.
Note: if the cookie does not use one of the prefixes by default, and you can't customize the name of the cookie, the cache exclusion will only work on the WP Rocket side while APO will still serve the cache.