Why does CloudFlare APO conflict with LiteSpeed LScache?

Ask A Question


LiteSpeed and CloudFlare APO. Not a good idea


Increasingly, it is being observed that many users of the LiteSpeed Cache plugin for WordPress are also using Cloudflare APO, despite clear warnings from LiteSpeed Cache about potential conflicts. This warning is not arbitrary and does not aim to block competing cache plugins. But what are the actual reasons for these conflicts? This post will address these questions and more.

Note: It doesn't matter if you have the CloudFlare APO Plugin installed or if you have set a native Configuration to cache dynamic Sources in CloudFlare Dashboard. Whenever a CloudFlare Cache Rule is defined for dynamic Sources it conflicts with LiteSpeed!

What is the Difference Between LiteSpeed LScache and Cloudflare APO?



To better understand the conflict, it is crucial to know the differences between the two caching and optimization solutions. Aside from specific details of their functions, the main differences are minimal. Both LiteSpeed LScache and Cloudflare APO provide a page cache. A page cache is URL-based, creating a static copy of a dynamically generated HTML page, which is stored either on the server or, in the case of Cloudflare, on a CDN node. Once a page is cached, only the content of the static copy is delivered, eliminating the need for PHP execution and database queries, which explains the faster loading time.

The fundamental caching principle is essentially the same for LiteSpeed and Cloudflare, although Cloudflare performs caching through its CDN node. Note that LiteSpeed Cache only caches dynamically generated content, such as the main document and further PHP-generated requests. Cloudflare, on the other hand, also caches static sources, which is not necessarily an advantage over LiteSpeed, as it can often lead to disadvantages. Caching static sources is more a feature of a CDN than a page cache. Additionally, Cloudflare's caching is limited to the nearest CDN node. Users not on the same CDN node will not receive the cached page. This is crucial to understanding whether any CDN can always be faster than the origin host.

Why is Cloudflare APO in Conflict with LiteSpeed LScache?



Since there are no fundamental differences between Cloudflare APO and LiteSpeed LScache regarding page caching, it should be evident that 1 page cache plus 1 page cache does not equal 2 page caches. Cloudflare, being a CDN, is positioned in front of the origin host, so a request for a cached page from Cloudflare is answered only by the CDN node. Whether the same URL is also cached by LiteSpeed at the origin host provides neither advantage nor disadvantage because a cached request by Cloudflare does not include the origin host. Changes to the origin host will only be visible after the Cloudflare cache is purged. This is the key reason why both caching solutions are in conflict.

Both LiteSpeed and Cloudflare allow defining so-called cache vary rules, which create different cache copies based on HTTP parameters. While LiteSpeed defines these rules through PHP and can also use modRewrite rules in the .htaccess file for cached pages, Cloudflare does not support these rules in the .htaccess file.

The LiteSpeed Cache plugin for WordPress uses various cache vary rules not supported by Cloudflare. Therefore, using Cloudflare APO causes the following LiteSpeed Cache features to stop working:

  • Guest Mode
  • Mobile Cache
  • WebP Replacement
  • JS/CSS Minify
  • JS/CSS Combine

Using Cloudflare APO with LiteSpeed LScache means foregoing these features, which significantly affects the PageSpeed score.

What Are the Drawbacks of Not Using LiteSpeed LScache and Cloudflare APO Together?


The disadvantages of using both caching solutions simultaneously outweigh the drawbacks of using Cloudflare APO alone. However, Cloudflare can still be used as a CDN, even though without caching, a CDN primarily functions as a DNS provider that resolves IP addresses. Cloudflare's security features are very useful regardless of caching. Comparable protection could be set up on the origin host, but blocking unwanted traffic incurs additional costs and server load. Therefore, it is often better to implement security measures through a proxy like Cloudflare. However, the complexity of Cloudflare's filtering rules can increase response times.

Is Cloudflare Always Faster Than the Origin Host?


Not necessarily. Cloudflare or any other CDN provider can sometimes worsen loading times. The Cloudflare APO slogan "An easy way to make WordPress sites load 72% faster" should not be generalized, as several factors must be met for Cloudflare to be faster than the origin host.

The first factor is the distance between the CDN node and the user's location. While data transfer over the internet is almost instantaneous, it does not happen directly between the CDN node and the client, which also applies without a CDN. The decentralized nature of the internet requires a request to contact multiple routers, which can lead to delays. The resolution of IP addresses affects loading time. A CDN advantage shows only on the first request. Once the browser knows where an IP address resolves, the CDN advantage diminishes, especially for static sources.

For Cloudflare or any other CDN to be faster, the following conditions must be met:

  • IP address resolution via Cloudflare must be faster than via the origin host.
  • The distance between a CDN node and the client must be less than between the origin host and the client.
  • The requested content must already be in the CDN node's cache.

All these conditions must be met; otherwise, Cloudflare APO will not provide significant benefits. All CDN nodes must cache the content of a URL; otherwise, the request will be forwarded to the origin host. This dramatically reduces the advantage of CDN caching. The Cloudflare slogan "An easy way to make WordPress sites load 72% faster" only holds if all conditions are met.

Do I Really Need Cloudflare or Any Other CDN?


Whether you need Cloudflare APO or any other CDN depends significantly on the location of your website visitors. The basic rule is simple: if most of your visitors are from the same location as your server, a CDN like Cloudflare will likely be slower than the origin host. Using a CDN is most beneficial when your site's content is of international interest and most visitors come from other countries.

More useful Posts