• Resolved robertrosanke

    (@robertrosanke)


    Hello.

    We are in the process of optimizing our shop.
    We are currently trying to load fewer resources in the frontend.

    Our first tests show good improvements.

    We have found CSS files with the following handles and would like to remove them from all pages where it is safe to do so.

    • wc-blocks-vendors-style
    • wc-blocks-style

    By default, the files are loaded on each page.

    We would like to only load the WC Block CSS when actually using WooCommerce Blocks on a page.

    To be on the safe side, we currently keep both CSS files in the frontend if it is a WooCommerce page or a WooCommerce block was found in the main content:

    $is_wc_page = is_woocommerce() || is_cart() || is_checkout();
    
    global $post;
    $blocks = WFA_WP_Block_Utils::get_blocks($post->post_content);
    
    // checks if there is at least one block['blockName'] containing "woocommerce" 
    $has_page_wc_block = WFA_WP_Block_Utils::has_content_block($blocks, 'woocommerce');
    
    $is_required = $is_wc_page || $has_page_wc_block;
    if(!$is_required) {
      // wp_dequeue_style....
    }

    Is it safe to remove both files if no WooCommerce blocks are found in the post content? So also for WooCommerce pages?

    Then we could remove $is_wc_page and get an improvement on many product and category pages as well.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @robertrosanke

    I didn’t try it myself, but I think it will not cause any issue if you hide both CSS on the pages where those modules are not using.

    You can give it a try and if it doesn’t effect on the website layout then you can keep removing those files where you’re not using those modules.

    Thanks!

    Thread Starter robertrosanke

    (@robertrosanke)

    Thanks for the feedback.

    We just went live with the customization right now.
    Apparently it works and we can also eliminate the block styles on WooCommerce pages.

    Very good.

    Topic can be closed.
    Thanks.

    Hi @robertrosanke

    You’re welcome, glad to know it’s working fine. If you have any new questions, please create a new ticket.

    Cheers!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Is it safe to remove WC Blocks CSS when not using WooCommerce Blocks on a page?’ is closed to new replies.