Join the community today
Become a Member

Cloudflare Cloudflare 12th Birthday Week Announcements

Discussion in 'Domains, DNS, Email & SSL Certificates' started by eva2000, Sep 28, 2022.

  1. eva2000

    eva2000 Administrator Staff Member

    54,647
    12,230
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,799
    Local Time:
    8:11 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    This week is Cloudflare's 12th birthday and they have a full week of birthday announcements you can find on their blog at https://blog.cloudflare.com/tag/birthday-week/ :D

    Some worthy announcements that most Centmin Mod users will like is the move away from legacy Cloudflare Page Rules to a more flexible set of Cloudflare Origin, Dynamic Redirect, Cache, Configuration Rules. If you're familiar with Cloudflare's existing Firewall and Transform Rule expression field method, then you'd be at home for Cloudflare Origin, Dynamic Redirect, Cache, Configuration Rules :)
    So with [Cache Rules](https://blog.cloudflare.com/introducing-cache-rules/), it essentially means the old Bypass Cache On Cookie Page Rule reserved from Business or higher plans is now available to all Cloudflare plans - free and Pro as well via Cache Rules. I know a lot of folks who will be happy with this :D

    cf-cache-rules-01.png


    cf-cache-rules-bypass-on-cookie-01.png
     
  2. rdan

    rdan Well-Known Member

    5,446
    1,408
    113
    May 25, 2014
    Ratings:
    +2,201
    Local Time:
    6:11 AM
    Mainline
    10.2
    This will save me $20+ per month using CF Worker, nice!

    Hm, I don't see this Cache Rules rules on my Pro plan.
     
    Last edited by a moderator: Sep 28, 2022
  3. eva2000

    eva2000 Administrator Staff Member

    54,647
    12,230
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,799
    Local Time:
    8:11 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Try hard refreshing dashboard page or logging out and back in?
     
  4. rdan

    rdan Well-Known Member

    5,446
    1,408
    113
    May 25, 2014
    Ratings:
    +2,201
    Local Time:
    6:11 AM
    Mainline
    10.2
    Tried both, all I can see is this:

    upload_2022-9-28_10-12-47.png

    Edit, see it now :D
    upload_2022-9-28_10-13-32.png
     
  5. deltahf

    deltahf Premium Member Premium Member

    587
    265
    63
    Jun 8, 2014
    Ratings:
    +489
    Local Time:
    5:11 PM
    Wow, good spot @eva2000. :D

    I can't see it yet but I am curious to play around with this as it may replace my custom Worker too. According to the Cache Rules documentation, you can even specify a custom cache key too, awesome! :cool: (FYI, for anyone reading, this is important because some important platforms like Facebook append a query string which was causing a lot of cache bypasses for FB users clicking onto our articles. Excluding the query string and using the base URL as the cache key gives a much higher cache hit rate.)

    I was using my custom CF Worker to accomplish cookie-based caching too but have been plagued by blank white cached pages as documented here. Basically, cached pages from some POPs would occasionally return an empty response, even though the page was successfully fetched and cached. It is a Cloudflare problem but I never could get much attention for it and it is extremely difficult to reproduce or troubleshoot.

    I have not updated that thread yet, but I did find a way to mitigate the problem by checking the cache's response before returning it to the user and re-fetching if needed. I set up some basic logging overnight to see how often it was happening and it was more common than I would have liked (the Vienna POP seems to be particularly affected).

    Hopefully Cache Rules will not be affected by this, but I assume they are using the same underlying system, so it will be interesting to see. I am also determining the cache-ability of certain pages (articles in WP) in my worker using custom headers sent from the origin server by my WP template. Not sure it will be an issue for me now as my Worker had to deal with a lot of requests that were never intended for it due to the fact that I could not use regex expressions on Worker paths, so I can probably re-think the whole system with Cache Rules in place. :)
     
  6. eva2000

    eva2000 Administrator Staff Member

    54,647
    12,230
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,799
    Local Time:
    8:11 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Haven't come across that issue myself but for Cloudflare Workers you'd get the most response if you join and ask on official Cloudflare Discord developer server instead of the their forums.

    You might also be able to use report-uri.com's NEL (Network Error Logging) to check for http.response.invalid.empty responses (see thumbnail screenshot). I don't have any recorded for this forum, blog or main centminmod.com site. You can limit report-uri's usage/billing by only adding their NEL headers via a Cloudflare Transform Response header on criteria like AS Num, Cookie, Country, Continent, Hostname and other fields.

    cf-transform-reponse-header-report-uri-nel-02.png
     
    Last edited: Oct 2, 2022
  7. rdan

    rdan Well-Known Member

    5,446
    1,408
    113
    May 25, 2014
    Ratings:
    +2,201
    Local Time:
    6:11 AM
    Mainline
    10.2
    Problem with Cache rules, the shortest Edge TTL I can configure is 1 hour.
     
  8. eva2000

    eva2000 Administrator Staff Member

    54,647
    12,230
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,799
    Local Time:
    8:11 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Edge TTL is still subject to your CF plans limits AFAIK. So CF Pro min Edge TTL = 1hr, CF Free min Edge TTL = 2hrs, CF Business was 30 mins but they changed it to be like CF Enterprise min Edge TTL down to 1 second

    This is on my Cloudflare Enterprise & Business Plans

    cf-cache-rules-edgettl-times-01.png

    For non CF Business/Enterprise plans, if you want Edge TTL with shorter times, you'd need to use Cloudflare Worker based caching to set your own Edge TTLs.
     
  9. deltahf

    deltahf Premium Member Premium Member

    587
    265
    63
    Jun 8, 2014
    Ratings:
    +489
    Local Time:
    5:11 PM
    Just an update on this, I've decided to stick with my custom Worker to control caching, now that I've figured out how to prevent the empty page issue. There's just too much power available in fully scriptable Workers. :)

    More specifically, I'm doing several other things in my Worker which should provide higher cache rates and more accurate analytics data in GA4!

    I get a lot of traffic to my articles from Facebook, and Facebook is now appending unique '?fbclid=XXX...' parameters to every visit from FB. I noticed this was effectively acting as a cache-buster for each user who clicked through to my site from FB. FB users were not seeing cached pages, and the unique URLs they were accessing would never be used by anyone else again. Of course, this is a problem with other click tracking parameters as well.

    To mitigate this, I am stripping the query strings and using the base URL as the cache key for Cloudflare:

    Code:
    const url = new URL(request.url)
    const cacheKey = url.origin + url.pathname
    let response = await cache.match(cacheKey)
    This means that every public user can access or prime the cache no matter what URL parameters they are using.

    The "fbclid" parameter also causes an issue with Google Analytics 4, which does not allow you to exclude individual parameters from your reports. This means that each click to your site from Facebook will be tracked as a unique page in GA4, skewing your statistics and under-reporting traffic to specific pages. To solve this, I have now started stripping the fbclid parameter entirely and 301-redirecting the user to the base URL before the cache is touched inside the Worker:

    Code:
    if (url.searchParams.get("fbclid")) {
      const strippedUrl = url.origin + url.pathname
      return Response.redirect(strippedUrl, 301)
    }
    
    Of course, if you are actually using FB retargeting this could cause problems.

    (Sorry, I know this has nothing to do with Cloudflare's 12th Birthday Week, but I thought it might be useful info to share! It's just tough to beat CF Workers. :D)
     
  10. eva2000

    eva2000 Administrator Staff Member

    54,647
    12,230
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,799
    Local Time:
    8:11 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Empty cache related to query strings or a separate issue?
    Nice, I ignore some query strings in my CF Workers too. But with Cloudflare Transform Rewrite URL rules now you can modify request query strings to be stripped and ignored by Cloudflare on specific criteria i.e. ASN, country, IP, referrer etc before it hits their edge servers. So you'd have finer grain control over when to ignore specific query strings etc
     
  11. deltahf

    deltahf Premium Member Premium Member

    587
    265
    63
    Jun 8, 2014
    Ratings:
    +489
    Local Time:
    5:11 PM
    Separate issue. :)
    I looked into Rewrite Rules but I couldn't get it working with what I was looking to accomplish. Decided it would be much easier to just write some JavaScript. :D
     
  12. eva2000

    eva2000 Administrator Staff Member

    54,647
    12,230
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,799
    Local Time:
    8:11 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Yeah CF Workers is a game changer - if you know how to use it :)