• Resolved juanwp22

    (@juanwp22)


    Hello, I have been using this excellent plugin on my sites for a long time and I had no problems configuring it. But yesterday I installed it on a new site and server that I’m testing (Oracle) and it gives me this error:

    2022-04-16-07-44-42-WP-Cloudflare-Super-Page-Cache-Reconnective-Healing-Practitioners-Word-Press<br />fotos de red<br />

    The only cache plugin I have is autooptimize and I already purged it.

    • This topic was modified 4 years, 1 month ago by juanwp22.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 16 through 18 (of 18 total)
  • Plugin Contributor iSaumya

    (@isaumya)

    You cannot just exclude cookies. You need to remove the plugin that are relying on those cookies. Regarding the header, you need to contact your host (if you have a managed WP hosting) as they will be able to help you better.

    Will removing the header through my hosting service fix the issue and enable the cache?

    As for cookies and plugins: I don’t quite understand how any site can work now without using cookies? …
    For example, I have code that sets a cookie so that a customer can see products that they have already viewed. Like heading “you watched”

    add_action( ‘template_redirect’, ‘recently_viewed_product_cookie’, 20 );

    function recently_viewed_product_cookie() {
    if ( ! is_product() ) {
    return;
    }

    if ( empty( $_COOKIE[ ‘woocommerce_recently_viewed_2’ ] ) ) {
    $viewed_products = array();
    } else {
    $viewed_products = (array) explode( ‘|’, $_COOKIE[ ‘woocommerce_recently_viewed_2’ ] );
    }

    if ( ! in_array( get_the_ID(), $viewed_products ) ) {
    $viewed_products[] = get_the_ID();
    }

    if ( sizeof( $viewed_products ) > 6 ) {
    array_shift( $viewed_products );
    }

    wc_setcookie( ‘woocommerce_recently_viewed_2’, join( ‘|’, $viewed_products ) );

    }

    add_shortcode( ‘recently_viewed_products’, ‘recently_viewed_products’ );

    function recently_viewed_products() {

    if( empty( $_COOKIE[ ‘woocommerce_recently_viewed_2’ ] ) ) {
    $viewed_products = array();
    } else {
    $viewed_products = (array) explode( ‘|’, $_COOKIE[ ‘woocommerce_recently_viewed_2’ ] );
    }

    if ( empty( $viewed_products ) ) {
    return;
    }

    $viewed_products = array_reverse( array_map( ‘absint’, $viewed_products ) );

    $title = ‘<h4>Вы смотрели</h4>’;

    $product_ids = join( “,”, $viewed_products );

    return $title . do_shortcode( “[products ids=’$product_ids’]” );

    }`

    As far as I understand, for the cache to work in your plugin, I need to abandon this code?…

    Plugin Contributor iSaumya

    (@isaumya)

    Will removing the header through my hosting service fix the issue and enable the cache?

    – Well your site had 2 problems. The plugin was unable to add it’s cache-control header as some other plugin or server rule is adding the cache-control header. BTW just checked your site now and it seems this plugin is disabled on your site now as I can’t see any response headers added by this plugin.

    As for cookies and plugins: I don’t quite understand how any site can work now without using cookies?

    – Cookies are an ancient thing that was always destructive to caching. You really have to understand how caching work. Simply speaking, when caching is enabled, the page which is being served by the cache, that page does not get generated by the server or PHP. Instead when the first time PHP generate and send that page the caching system cache that out to show to the future users.

    Now when you have cookeis it means those cookie values might be used inside the PHP to show dynamic data, so caching any page with cookies will theoretically means the cookies can never works when page is being served by cache or CDN, PHP is not getting executed instead the cached page HTML is being served.

    This is why in the modern day cookies are an ancient relic. Instead engineers are now rely more on Browser Local Storage API which stores data like cookies but accessed via JS and does not hamper caching in any ways. Check:
    https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
    https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage

    Hope this helps.

Viewing 3 replies - 16 through 18 (of 18 total)

The topic ‘Cache dont working’ is closed to new replies.