Is it safe to remove WC Blocks CSS when not using WooCommerce Blocks on a page?
-
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.
- The topic ‘Is it safe to remove WC Blocks CSS when not using WooCommerce Blocks on a page?’ is closed to new replies.