Jump to content

ProcessWire interferes with Cloudflare "cache everything"?


chcs
 Share

Recommended Posts

Because of some server issues, and page loading speed and performance, I've been using Cloudflare to set up "cache everything" page rules for various sites. Cloudflare, by default, only caches assets like css or jpgs, but not the actual document html that is created by the server on request. Setting "cache everything" changes that and allows Cloudflare to serve up the html directly (rules providing). This cuts down the initial TTFB (time to first byte) considerably, especially during high traffic or server attacks.

In order to tell whether Cloudflare is serving up an asset or not, you need to inspect the headers (break out your html inspectors and look at the network tab). In the response for the asset (jpg, css, document, etc) you'll see an attribute for "CF-CACHE-STATUS" and the associated value.

<?php
// include "../index.php";

$name = $_REQUEST["name"];
echo "<pre>";
echo "hello ?name=$name";

$number = 9;
while ($number > 0) {
    $result = $number - 1;
    echo "
        $number - 1 = $result
    ";
    $number--;
}

The above is the code in a file named https://www.chas.us/test/no_pw.php

  1. With your developer tools tuned to the network tab you can load this page.
  2. you can provide it different querystrings in order to trigger Cloudflare to react and cache it, while you study the cf-cache-status flag
  3. https://www.chas.us/test/no_pw.php?name=chcs
  4. CF-CACHE-STATUS = MISS
  5. reload
  6. CF-CACHE-STATUS = HIT

What does this mean? It means that you made a request, through Cloudflare, to get the page. Cloudflare realized it didn't have a copy of it, so it went to the server directly for it. When the server created the html, Cloudflare served it to you and stored it. However, on your subsequent reloads, Cloudflare will realize that it has the copy and serve it directly to you, without requiring your server to execute php to recreate it. You have effectively "HIT" the cached version.

I have a second file where I merely un-comment the include line that bootstraps Processwire. I did this as the most bare-bones attempt at troubleshooting what I was seeing in a conventional Processwire site/templates driven website.

  1. With your developer tools tuned to the network tab...
  2. And following the same procedure you did above
  3. https://www.chas.us/test/pw_included.php?name=ohhello
  4. CF-CACHE-STATUS = BYPASS
  5. reload
  6. CF-CACHE-STATUS = BYPASS

As you can see, I am not using any Processwire methods to output code, but when I include it when generating the page... something about it causes Cloudflare to not cache the generated page. This is a problem whether I am bootstrapping PW (like the above bare-bones example) or whether I am using it in the standard conventional way for a proper website. Cloudflare seems to always get bypassed so that the server can create the the page. I've also attempted to change the template cache value to see if that would somehow enable Cloudflare to serve the page, but it does not.

Not sure how to proceed, as this finding seems to indicate that I cannot leverage the speed of Cloudflare on websites that employ Processwire to generate the html markup.

Help!

 

 

Screen Shot 2019-10-30 at 1.13.52 PM.png

Link to comment
Share on other sites

  • 2 years later...

I've been playing with CloudFlare's cache everything feature to serve a site that's hardly ever updated from the edge. It works amazingly well on non-PW sites, speed is so fast it seems you're serving the site locally. But I'm having the same issue as @chcs with that PW site, all assets are fully cached but the page. You can easily check this using Dr Flare's extension on Chrome.

Anyone knows why the response header is set to no-cache for HTML pages served by ProcessWire, and how we can bypass this?

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...