Forum Replies Created

Viewing 15 replies - 31 through 45 (of 108 total)
  • Thread Starter Nate

    (@goseongguy)

    Perfect, thank you!

    Thread Starter Nate

    (@goseongguy)

    Hi Arya,

    For the Delay CSS feature: Any chance you might be able to rename the userInteractionEvents variable (or some other tweak) to avoid conflicts with the Flying Scripts plugin?

    I edited $print_delay_css_interaction_inline_script in optimize-more-css/includes/functions/delay-css-on-interaction.php by renaming userInteractionEvents to userInteractionEvents2, and now the delay CSS feature works!

    It would be ideal though to not have to manually edit the plugin on each update, and in case any of the other 20,000+ Flying Scripts users try your plugin, they would encounter the same.

    Plugin working great now.

    Cheers,
    Nate

    Thread Starter Nate

    (@goseongguy)

    Hello Arya,
    Thanks for the prompt response. No big deal, it’s just helpful.

    Aha, I think I see now that this is only activated when logged out. I was looking for a change while logged in to wp-admin.

    However I do see a console error:
    Uncaught SyntaxError: Identifier 'userInteractionEvents' has already been declared (at (index):99:578)

    Could the error be related to a conflict with another plugin I’m using Flying Scripts which delays JS?

    Here is a URL: https://goseongguy.com/the-hideout-bakery-cafe/

    This is with the following IDs async, entering keywords as below:

    trp-floater-language-switcher-style-css
    trp-language-switcher-style-css

    I also tried to make a CSS file delayed (which doesn’t work due to the console error I believe) using the keyword:

    non-critical-css

    Thanks,
    Nate

    • This reply was modified 2 years, 5 months ago by Nate.
    • This reply was modified 2 years, 5 months ago by Nate.
    Thread Starter Nate

    (@goseongguy)

    Interesting! When I do as you say above in the HTTP tab, the worker header is there!

    View post on imgur.com

    200 OK
    cache-control:s-maxage=31536000, max-age=60
    cf-cache-status:MISS
    cf-ray:6fb8018b89eb6339-ORD
    content-type:text/html; charset=UTF-8
    date:Wed, 13 Apr 2022 23:33:19 GMT
    expect-ct:max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
    host-header:c2hhcmVkLmJsdWVob3N0LmNvbQ==
    last-modified:Wed, 13 Apr 2022 21:18:25 GMT
    referrer-policy:no-referrer-when-downgrade
    server:cloudflare
    transfer-encoding:chunked
    vary:Accept-Encoding
    x-content-type-options:nosniff
    x-frame-options:SAMEORIGIN
    x-wp-cf-fallback-cache:1
    x-wp-cf-super-cache:cache
    x-wp-cf-super-cache-active:1
    x-wp-cf-super-cache-cache-control:s-maxage=31536000, max-age=60
    x-wp-cf-super-cache-worker-status:miss
    x-xss-protection:1; mode=block

    But the header is not there when the page is visited directly through a browser from people like you and me.

    • This reply was modified 2 years, 7 months ago by Nate.
    Thread Starter Nate

    (@goseongguy)

    That fixed it! Somehow the mu-plugins-old directory had a file permission of 0000, so changing it to 0755 allowed UpdraftPlus to delete the old directories and that subsequently allowed backups to complete successfully.

    Thank you!

    Thread Starter Nate

    (@goseongguy)

    And when I click the Preview tab, I see this: https://imgur.com/mpQLMAC

    Uh oh…
    Error communicating with origin server swcfpc_worker_1619093168.natedolesh1465.workers.dev
    Details
    TLS peer’s certificate is not trusted; reason = Hostname mismatch

    The Service Workers Cache API is currently unimplemented in the Cloudflare Workers Preview. Cache API operations which would function normally in production will not throw any errors, but will have no effect. Notably, Cache.match() will always return undefined, and Cache.delete() will always return false. When you deploy your script to production, its caching behavior will function as expected.
    handleRequest @ worker.js:304
    (anonymous) @ worker.js:486

    • This reply was modified 2 years, 7 months ago by Nate.
    Thread Starter Nate

    (@goseongguy)

    Here is a a screenshot of that: https://imgur.com/tl4huzA

    Looking through the worker code I can see 4 lines where the header gets set to either bypass, hit, or miss. For example:

     // Set the worker status as miss and put the item in CF cache
              response.headers?.set('x-wp-cf-super-cache-worker-status', 'miss')
    Thread Starter Nate

    (@goseongguy)

    When I click Edit on the previous screen capture, it just shows a popup with the same info: https://imgur.com/H6MkUP6
    Is that what you mean, or is there a different way to view/edit the script?

    Do I need to click Manage Workers, and “Set up your free custom Cloudflare Workers? subdomain”? That’s something else, right? Or maybe I had to do that all along?

    Thread Starter Nate

    (@goseongguy)

    Here is the page rules section. They are all disabled: https://imgur.com/Q6rgWbT

    Thread Starter Nate

    (@goseongguy)

    Here is a screenshot of that part: https://imgur.com/pyLvPGp

    Maybe I will try to remove the plugin and re-install it when I get a chance.

    Thread Starter Nate

    (@goseongguy)

    Hello Saumya,
    I appreciate your responsiveness.

    I contacted host support again to disable the server cache, and waited 1 day, and the x-nginx-cache header remains gone. (He said the previous agent didn’t disable the cache properly.) So that shouldn’t be in play anymore.

    However, the X-WP-CF-Super-Cache-Worker-Status is still not there. I re-toggled and re-enabled caching a few times and made sure to check all that you mentioned previously.

    Is there anything else we can try or look at?

    • This reply was modified 2 years, 7 months ago by Nate.
    Thread Starter Nate

    (@goseongguy)

    Just noticed the nginx header is back. The host agent told me they removed it at the source. But it seems they either didn’t do it properly or they faked it by only taking it out of the WordPress part of the .htaccess (it just gets regenerated).

    Thread Starter Nate

    (@goseongguy)

    Have you made sure that the worker mode is enabled on the site

    I’m not sure what you mean, but Worker Mode is enabled in the plugin settings.

    There is no other worker present in the CF dashboard.

    The x-nginx-cache header has been removed.

    Is there any other info I can provide? Here is the log (high verbosity) from when I disable page caching to enable it.

    For some reason I sometimes I see the log mention WP_CACHE not being found, but it’s there in wp-config.php.

    [2022-04-05 04:57:05] [cloudflare::cloudflare_get_browser_cache_ttl] Request https://api.cloudflare.com/client/v4/zones/83fce0d845bc43b75874f930809eb136/settings/browser_cache_ttl
    [2022-04-05 04:57:06] [cloudflare::cloudflare_get_browser_cache_ttl] Response {"result":{"id":"browser_cache_ttl","value":0,"modified_on":"2021-04-24T15:30:29.469221Z","editable":true},"success":true,"errors":[],"messages":[]}
    [2022-04-05 04:57:06] [cloudflare::cloudflare_set_browser_cache_ttl] Request URL: https://api.cloudflare.com/client/v4/zones/83fce0d845bc43b75874f930809eb136/settings/browser_cache_ttl
    [2022-04-05 04:57:06] [cloudflare::cloudflare_set_browser_cache_ttl] Request body: {"value":0}
    [2022-04-05 04:57:06] [cloudflare::cloudflare_set_browser_cache_ttl] Response: {"result":{"id":"browser_cache_ttl","value":0,"modified_on":"2021-04-24T15:30:29.469221Z","editable":true},"success":true,"errors":[],"messages":[]}
    [2022-04-05 04:57:06] [cloudflare::worker_route_get_list] Request https://api.cloudflare.com/client/v4/zones/83fce0d845bc43b75874f930809eb136/workers/routes
    [2022-04-05 04:57:06] [cloudflare::worker_route_get_list] Response {
      "result": [],
      "success": true,
      "errors": [],
      "messages": []
    }
    
    [2022-04-05 04:57:06] [cloudflare::get_account_ids] Request https://api.cloudflare.com/client/v4/accounts?page=1&per_page=20&direction=desc
    [2022-04-05 04:57:06] [cloudflare::get_account_ids] Response: {"result":[{"id":"83e44cf10b74dd1d19a4513ad00416ba","name":"[email protected]'s Account","type":"standard","settings":{"enforce_twofactor":false,"access_approval_expiry":null,"use_account_custom_ns_by_default":false},"legacy_flags":{"enterprise_zone_quota":{"maximum":0,"current":0,"available":0}},"created_on":"2020-09-20T08:38:24.556084Z"}],"result_info":{"page":1,"per_page":20,"total_pages":1,"count":1,"total_count":1},"success":true,"errors":[],"messages":[]}
    [2022-04-05 04:57:06] [cloudflare::worker_get_list] I'm using the account ID: 83e44cf10b74dd1d19a4513ad00416ba
    [2022-04-05 04:57:06] [cloudflare::worker_get_list] Request https://api.cloudflare.com/client/v4/accounts/83e44cf10b74dd1d19a4513ad00416ba/workers/scripts
    [2022-04-05 04:57:07] [cloudflare::worker_get_list] Response: {
      "result": [],
      "success": true,
      "errors": [],
      "messages": []
    }
    
    [2022-04-05 04:57:07] [cloudflare::worker_upload] I'm using the account ID: 83e44cf10b74dd1d19a4513ad00416ba
    [2022-04-05 04:57:07] [cloudflare::worker_upload] Request https://api.cloudflare.com/client/v4/accounts/83e44cf10b74dd1d19a4513ad00416ba/workers/scripts/swcfpc_worker_1619093168
    [2022-04-05 04:57:07] [cloudflare::worker_upload] Response: {
      "result": {
        "id": "swcfpc_worker_1619093168",
        "etag": "bf5cf3b58a85fc1f7f372b4ccf37cb65825df7283121ef02bfdeb5a913639ea2",
        "handlers": [
          "fetch"
        ],
        "modified_on": "2022-04-05T04:57:07.429512Z",
        "created_on": "2022-04-05T04:57:07.429512Z",
        "usage_model": "bundled",
        "script": "// Worker version: 2.7.1\n// Default cookie prefixes for cache bypassing\nconst DEFAULT_BYPASS_COOKIES = [\n  'wordpress_logged_in_',\n  'comment_',\n  'woocommerce_',\n  'wordpressuser_',\n  'wordpresspass_',\n  'wordpress_sec_',\n  'yith_wcwl_products',\n  'edd_items_in_cart',\n  'it_exchange_session_',\n  'comment_author',\n  'dshack_level',\n  'auth',\n  'noaffiliate_',\n  'mp_session',\n  'mp_globalcart_'\n]\n\n// Third party query parameter that we need to ignore in a URL\nconst THIRD_PARTY_QUERY_PARAMETERS = [\n  'fbclid',\n  'fb_action_ids',\n  'fb_action_types',\n  'fb_source',\n  '_ga',\n  'age-verified',\n  'ao_noptimize',\n  'usqp',\n  'cn-reloaded',\n  'klaviyo',\n  'gclid',\n  'utm_source',\n  'utm_medium',\n  'utm_campaign',\n  'utm_content',\n  'utm_term',\n  'ref',\n  'utm_term',\n  'hemail'\n]\n\n// Origin Server Response Codes : \n// Includes response status codes for which the execution is stopped and server response of that time is returned\nconst ORIGIN_SERVER_UNUSUAL_RESPONSE_CODES = [\n  // Client Error Response Codes\n  400, 401, 403, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 421, 422, 423, 429, 431, 451,\n  // Server Error Response Codes\n  500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511,\n  // Redirection Response codes\n  301, 302, 307, 308\n]\n\n/**\n * Function to check if the response status code is within the list \n * of our ORIGIN_SERVER_UNUSUAL_RESPONSE_CODES array and if so, then\n * return TRUE else FALSE\n *\n * @param {Response} response - The origin server response\n * @return {Boolean} has_unusual_response_code - If the response has a status code is \n * within the defined list then return TRUE else FALSE\n */\nfunction has_unusual_origin_server_response_code(response) {\n  if( ORIGIN_SERVER_UNUSUAL_RESPONSE_CODES.includes( response?.status ) ) {\n    response.headers?.set('x-wp-cf-super-cache-worker-origin-response', response.status)\n    return true\n  } else {\n    return false\n  }\n}\n\n/**\n * Function to normalize the URL by removing promotional query parameters from the URL and cache the original URL\n * @param {Object} event - Event Object\n * @return {URL} reqURL - Request URL without promotional query strings\n */\nfunction url_normalize(event) {\n  try {\n    // Fetch the Request URL from the event\n    // Parse the URL for better handling\n    const reqURL = new URL(event?.request?.url)\n\n    // Loop through the promo queries (THIRD_PARTY_QUERY_PARAMETERS) and see if we have any of these queries present in the URL, if so remove them\n    THIRD_PARTY_QUERY_PARAMETERS.forEach( (queryParam) =\u003e {\n\n      // Create the REGEX to text the URL with our desired parameters\n      const promoUrlQuery = new RegExp( '(\u0026?)(' + queryParam + '=\\\\S+)', 'g' )\n\n      // Check if the reqURL.search has these search query parameters\n      if(promoUrlQuery.test( reqURL.search )) {\n\n        // The URL has promo query parameters that we need to remove\n        const urlSearchParams = reqURL.searchParams\n\n        urlSearchParams.delete(queryParam)\n      }\n    } )\n\n    return reqURL\n\n  } catch (err) {\n    return {\n      error: true,\n      errorMessage: <code>URL Handling Error: ${err.message}</code>,\n      errorStatusCode: 400\n    }\n  }\n}\n\n/**\n * Function to check if the current request should be BYPASSed or Cached based on exclusion cookies\n * entered by the user in the plugin settings\n * @param {String} cookieHeader - The cookie header of the current request\n * @param {Array} cookies_list - List of cookies which should not be cached\n * @return {Boolean} blackListedCookieExists - If blacklisted cookie exists in the current request\n */\nfunction are_blacklisted_cookies(cookieHeader, cookies_list) {\n  let blackListedCookieExists = false\n\n  // Make sure both cookieHeader \u0026 cookies_list are defined \u0026 the length of both cookieHeader \u0026 cookies_list \u003e 0\n  if (\n    cookieHeader?.length \u003e 0 \u0026\u0026\n    cookies_list?.length \u003e 0\n  ) {\n    // Split the received request cookie header by semicolon to an Array\n    const cookies = cookieHeader.split(';')\n\n    // Loop through the cookies in the request header and check if there is any cookie present there\n    // which is also mentioned in our bypassed cookies array\n    // if there is then set blackListedCookieExists as true and break out of the loops\n    cookies.every((cookie) =\u003e {\n\n      cookies_list.every((single_black_list_cookie) =\u003e {\n        if (cookie.trim().includes(single_black_list_cookie.trim())) {\n          blackListedCookieExists = true\n          // Found item. Break out from the loop\n          return false\n        }\n\n        // Otherwise continue the loop\n        return true\n      })\n\n      // Check if blackListedCookieExists is true then break out of this loop. Else continue the loop\n      return blackListedCookieExists ? false : true\n    })\n  }\n\n  return blackListedCookieExists // value -\u003e TRUE | FALSE\n}\n\n/**\n * Function to add extra response headers for BYPASSed Requests\n * @param {Response} res - The response object\n * @param {String} reason - The string that hold the bypass reason\n */\nfunction add_bypass_custom_headers(res, reason) {\n  if (res \u0026\u0026 (reason?.length \u003e 0)) {\n    // BYPASS the request and add our custom headers\n    res?.headers?.set('x-wp-cf-super-cache-worker-status', 'bypass')\n    res?.headers?.set('x-wp-cf-super-cache-worker-bypass-reason', reason)\n    res?.headers?.set('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')\n  }\n}\n\n/**\n * The function that handles the Request\n * @param {Object} event - Received Event object\n * @return {Response} response - Response object that is being returned to the user\n */\nasync function handleRequest(event) {\n\n  const request = event?.request\n  const requestURL = url_normalize(event)\n\n  // Check if we have received any error in the url_normalize() call, if so return that error message\n  if( requestURL?.error ) {\n    return new Response( \n      requestURL.errorMessage,\n      { status: requestURL.errorStatusCode, statusText: requestURL.errorMessage } \n    )\n  }\n\n  let response = false\n  let bypassCache = false\n  const bypassReason = {\n    'req_method': false,\n    'admin_req': false,\n    'file_path_ext': false,\n    'page_excluded': false,\n    'file_excluded': false,\n    'cookie': false\n  }\n  let bypassReasonDetails = ''\n  const cookieHeader = request?.headers?.get('cookie')\n  const reqDetails = {\n    'contentTypeHTML': false\n  }\n\n  // ---------------------------------------------------------\n  // Check - Bypass Request ? - Only Based on Request Headers\n  // ---------------------------------------------------------\n\n  // 1. BYPASS any requests whose request method is not GET or HEAD\n  const allowedReqMethods = ['GET', 'HEAD']\n  if (!bypassCache \u0026\u0026 request) {\n    if (!allowedReqMethods.includes(request.method)) {\n      bypassCache = true\n      bypassReason.req_method = true\n      bypassReasonDetails = <code>Caching not possible for req method ${request.method}</code>\n    }\n  }\n\n  // 2. BYPASS the cache for WP Admin HTML Requests \u0026 Any File That has /wp-admin/ in it \u0026 API endpoints\n  // Get the Accept header of the request being received by the CF Worker\n  const accept = request?.headers?.get('Accept')\n\n  if (!bypassCache \u0026\u0026 accept) {\n\n    // List of path regex that we will BYPASS caching\n    // Path includes - WP Admin Paths, WP REST API, WooCommerce API, EDD API Endpoints\n    const bypass_admin_path = new RegExp(/(\\/(wp-admin)(\\/?))/g)\n    const bypass_cache_paths = new RegExp(/(\\/((wp-admin)|(wc-api)|(edd-api))(\\/?))/g)\n\n    // List of file extensions to be BYPASSed\n    const bypass_file_ext = new RegExp(/\\.(xsl|xml)$/)\n\n    // Check if the request is for WP Admin endpoint \u0026 accept type includes text/html i.e. the main HTML request\n    if ( accept?.includes('text/html') ) {\n      reqDetails.contentTypeHTML = true \n    }\n\n    // Check if the request URL is an admin URL for HTML type requests\n    if ( reqDetails.contentTypeHTML \u0026\u0026 bypass_admin_path.test(requestURL.pathname) ) {\n      bypassCache = true\n      bypassReason.admin_req = true\n      bypassReasonDetails = 'WP Admin HTML request'\n\n    } else if ( bypass_cache_paths.test(requestURL.pathname) || bypass_file_ext.test(requestURL.pathname) ) {\n      // This is for files which starts with /wp-admin/ but not supposed to be cached\n      // E.g. /wp-admin/load-styles.php || /wp-admin/admin-ajax.php\n      // Also API endpoints and xml/xsl files to ensure sitemap isn't cached\n\n      bypassCache = true\n      bypassReason.file_path_ext = true\n      bypassReasonDetails = 'Dynamic File'\n    }\n  }\n\n  // 3. BYPASS the cache if DEFAULT_BYPASS_COOKIES is present in the request\n  // AND also only for the HTML type requests\n  if (\n    !bypassCache \u0026\u0026\n    reqDetails.contentTypeHTML \u0026\u0026\n    cookieHeader?.length \u003e 0 \u0026\u0026\n    DEFAULT_BYPASS_COOKIES.length \u003e 0\n  ) {\n\n    // Separate the request cookies by semicolon and create an Array\n    const cookies = cookieHeader.split(';')\n\n    // Loop through the cookies Array to see if there is any cookies present that is present in DEFAULT_BYPASS_COOKIES\n    let foundDefaultBypassCookie = false\n\n    cookies.every((cookie) =\u003e {\n\n      DEFAULT_BYPASS_COOKIES.every((cookie_prefix) =\u003e {\n\n        if (cookie.trim().startsWith(cookie_prefix.trim())) {\n          bypassCookieName = cookie.trim().split('=')\n          bypassCache = true\n          bypassReason.cookie = true\n          bypassReasonDetails = <code>Default Bypass Cookie [${bypassCookieName[0]}] Present</code>\n          foundDefaultBypassCookie = true\n\n          // Stop the loop\n          return false\n        }\n\n        // Otherwise continue the loop\n        return true\n      })\n\n      // Stop the loop if foundDefaultBypassCookie is TRUE else continue\n      return foundDefaultBypassCookie ? false : true\n    })\n  }\n\n  /**\n   * Check if the Request has been Bypassed so far.\n   * If not, then check if the request exists in CF Edge Cache \u0026 if it does, send it\n   * If it does not exists in CF Edge Cache, then check if the request needs to be Bypassed based on the headers\n   * present in the Response.\n   */\n  if (!bypassCache) { // bypassCache is still FALSE\n\n    // Check if the Request present in the CF Edge Cache\n    const cacheKey = new Request(requestURL, request)\n    const cache = caches?.default // Get global CF cache object for this zone\n\n    // Try to Get this request from this zone's cache\n    try {\n      response = await cache?.match(cacheKey)\n    } catch (err) {\n      return new Response( \n        <code>Error: ${err.message}</code>,\n        { status: 500, statusText: \"Unable to fetch cache from Cloudflare\" } \n      )\n    }\n\n    if (response) { // Cache is present for this request in the CF Edge. Nothing special needs to be done.\n\n      // This request is already cached in the CF Edge. So, simply create a response and set custom headers\n      response = new Response(response?.body, response)\n      response?.headers?.set('x-wp-cf-super-cache-worker-status', 'hit')\n\n    } else { // Cache not present in CF Edge. Check if Req needs to be Bypassed or Cached based on Response header data\n\n      // Fetch the response of this given request normally without any special parameters\n      // so that we can use the response headers set by the plugin at the server level\n      let fetchedResponse\n      try {\n        fetchedResponse = await fetch(request)\n      } catch(err) {\n        return new Response( \n          <code>Error: ${err.message}</code>,\n          { status: 500, statusText: \"Unable to fetch content from the origin server\" } \n        )\n      }\n\n      // If the above if check fails that means we have a good response and lets proceed\n      response = new Response(fetchedResponse.body, fetchedResponse)\n\n      // Check if the response has any unusual origin server response code \u0026 if so then return the response\n      if( has_unusual_origin_server_response_code(response) ) {\n        return response\n      }\n\n      // ---------------------------------------------------------\n      // Check - Bypass Request ? - Based on RESPONSE Headers\n      // ---------------------------------------------------------\n\n      // 4. BYPASS the HTML page requests which are excluded from caching (via WP Admin plugin settings or page level settings)\n      if (\n        !bypassCache \u0026\u0026\n        response?.headers?.get('content-type')?.includes('text/html') \u0026\u0026\n        !response?.headers?.has('x-wp-cf-super-cache-active')\n      ) {\n        bypassCache = true\n        bypassReason.page_excluded = true\n        bypassReasonDetails = 'This page is excluded from caching'\n      }\n\n      // 5. BYPASS the static files (non HTML) which has x-wp-cf-super-cache response header set to no-cache\n      if (!bypassCache \u0026\u0026\n        !response?.headers?.get('content-type')?.includes('text/html') \u0026\u0026\n        (response?.headers?.get('x-wp-cf-super-cache') === 'no-cache')\n      ) {\n        bypassCache = true\n        bypassReason.file_excluded = true\n        bypassReasonDetails = 'This file is excluded from caching'\n      }\n\n      // 6. BYPASS cache if any custom cookie mentioned by the user in the plugin settings is present in the request\n      // Check only for HTML type requests\n      if (\n        !bypassCache \u0026\u0026\n        cookieHeader?.length \u003e 0 \u0026\u0026\n        response?.headers?.get('content-type')?.includes('text/html') \u0026\u0026\n        response?.headers?.has('x-wp-cf-super-cache-cookies-bypass')\n      ) {\n        // Make sure the feature is enabled first\n        if (response?.headers?.get('x-wp-cf-super-cache-cookies-bypass') !== 'swfpc-feature-not-enabled') {\n\n          // Get the list of cookie names entered by the user in the plugin settings\n          let cookies_blacklist = response?.headers?.get('x-wp-cf-super-cache-cookies-bypass')\n\n          if (cookies_blacklist?.length \u003e 0) {\n\n            // Split the received cookie list with | separated and make an Array\n            cookies_blacklist = cookies_blacklist.split('|')\n\n            if (are_blacklisted_cookies(cookieHeader, cookies_blacklist)) {\n              bypassCache = true\n              bypassReason.cookie = true\n              bypassReasonDetails = 'User provided excluded cookies present in request'\n            }\n          }\n        }\n      }\n\n      //-----------------------------------------------------\n      // Check if the request needs to be BYPASSed or Cached\n      //-----------------------------------------------------\n      if (!bypassCache) { // bypassCache is still FALSE. Cache the item in the CF Edge\n\n        // Check if the response status code is not 206 or request method is not HEAD to cache using cache.put(), \n        // as any request with status code === 206 or req.method HEAD cache.put() will not work. \n        // More info: https://developers.cloudflare.com/workers/runtime-apis/cache#put\n        if (response.status !== 206 || request?.method !== 'HEAD') {\n\n          // If the response header has x-wp-cf-super-cache-active overwrite the cache-control header provided by the server value with x-wp-cf-super-cache-active value just to be safe\n          if (response.headers?.has('x-wp-cf-super-cache-active')) {\n            response.headers?.set('Cache-Control', response.headers?.get('x-wp-cf-super-cache-cache-control'))\n          }\n\n          // Set the worker status as miss and put the item in CF cache\n          response.headers?.set('x-wp-cf-super-cache-worker-status', 'miss')\n\n          // Add page in cache using cache.put()\n          try {\n            event.waitUntil( cache.put( cacheKey, response.clone() ) )\n          } catch (err) {\n            return new Response( \n              <code>Cache Put Error: ${err.message}</code>,\n              { status: 500, statusText: <code>Cache Put Error: ${err.message}</code> } \n            )\n          }\n\n        } else {\n\n          // Try to fetch this request again with cacheEverything set to TRUE as that is the only way to cache it\n          // More info: https://developers.cloudflare.com/workers/runtime-apis/request#requestinitcfproperties\n          try {\n            response = await fetch(request, { cf: { cacheEverything: true } })\n          } catch (err) {\n            return new Response( \n              <code>Error: ${err.message}</code>,\n              { status: 500, statusText: \"Unable to fetch content from the origin server with cacheEverything flag\" } \n            )\n          }\n\n          response = new Response(response.body, response)\n\n          // Check if the response has any unusual origin server response code \u0026 if so then return the response\n          if( has_unusual_origin_server_response_code(response) ) {\n            return response\n          }\n\n          // Set the worker status as miss and put the item in CF cache\n          response.headers?.set('x-wp-cf-super-cache-worker-status', 'miss')\n\n        }\n      } else { // bypassCache -\u003e TRUE || Bypass the Request\n\n        // BYPASS the request and add our custom headers\n        add_bypass_custom_headers(response, bypassReasonDetails)\n      }\n\n    }\n\n  } else { // bypassCache -\u003e TRUE\n\n    // Fetch the request from the origin server and send it by adding our custom bypass headers\n    let bypassedResponse\n    try {\n      bypassedResponse = await fetch(request)\n    } catch (err) {\n      return new Response( \n        <code>Error: ${err.message}</code>,\n        { status: 500, statusText: \"Unable to fetch the bypassed content from the origin server\" } \n      )\n    }\n\n    response = new Response(bypassedResponse?.body, bypassedResponse)\n\n    // Check if the response has any unusual origin server response code \u0026 if so then return the response\n    if( has_unusual_origin_server_response_code(response) ) {\n      return response\n    }\n\n    // BYPASS the request and add our custom headers\n    add_bypass_custom_headers(response, bypassReasonDetails)\n  }\n\n  return response\n}\n\n/**\n * Adding event lister to the fetch event to catch the requests and manage them accordingly\n * @param {Object} event \n */\naddEventListener('fetch', event =\u003e {\n  try {\n    return event.respondWith(handleRequest(event))\n  } catch (e) {\n    return event.respondWith( \n      new Response( \n        <code>Error thrown: ${err.message}</code>,\n        { status: 500, statusText: <code>Error thrown: ${err.message}</code> } \n      ) \n    )\n  }\n})",
        "size": 5116
      },
      "success": true,
      "errors": [],
      "messages": []
    }
    
    [2022-04-05 04:57:07] [cloudflare::worker_route_create] Request URL: https://api.cloudflare.com/client/v4/zones/83fce0d845bc43b75874f930809eb136/workers/routes
    [2022-04-05 04:57:08] [cloudflare::worker_route_create] Response: {
      "result": {
        "id": "4a2589ac40814f14882f20f016d0e48f",
        "request_limit_fail_open": false
      },
      "success": true,
      "errors": [],
      "messages": []
    }
    
    [2022-04-05 04:57:08] [cloudflare::purge_cache] Request URL: https://api.cloudflare.com/client/v4/zones/83fce0d845bc43b75874f930809eb136/purge_cache
    [2022-04-05 04:57:08] [cloudflare::purge_cache] Request Body: {"purge_everything":true}
    [2022-04-05 04:57:09] [cloudflare::purge_cache] Response: {
      "result": {
        "id": "83fce0d845bc43b75874f930809eb136"
      },
      "success": true,
      "errors": [],
      "messages": []
    }
    
    [2022-04-05 04:57:09] [fallback_cache::fallback_cache_add_define_cache_wp_config] Constant WP_CACHE does not exists. I will try to add in into wp-config.php
    Thread Starter Nate

    (@goseongguy)

    Thank you for confirming. I have tried updating the settings, disabling the page cache and enabling, a few times. The issue is the same.

    In my Cloudflare account, I have no page rules active. There are 3 old ones but they’ve been disabled a long time ago.
    And I do see the worker route https://goseongguy.com/* show up in the Cloudflare dashboard when page caching is active.

    I have some snippets in my .htaccess for things like a few security headers, blocking all wp-includes folders and files, block external POST, blocks some XSS attacks, etc. Could this be a potential issue? I can share the .htaccess snippets if it would be helpful. I tried removing the custom .htaccess code but it doesn’t seem to affect the issue.

    Otherwise, what else can we look into?

    Thread Starter Nate

    (@goseongguy)

    These are additional styles that break validation:

    .uagb-icon-list-repeater{line-height: em;}
    .uagb-icon-list__label{line-height: em;}

Viewing 15 replies - 31 through 45 (of 108 total)