• Resolved dapperchap

    (@dapperchap)


    Hello,
    What is the purpose of “wc_product_block_data” huge block of code that gets injected to the page?

    
    <script type="text/javascript">
    		var c = document.body.className;
    		c = c.replace(/woocommerce-no-js/, 'woocommerce-js');
    		document.body.className = c;
    	</script>
    			<script type="text/javascript">
    			var wc_product_block_data = JSON.parse( decodeURIComponent( '%7B%22min_columns%22%3A1%2C%22max_columns%22%3A6%2C%22default_columns%22%3A3%2C%22min_rows%22%3A1%2C%22max_rows%22%3A6%2C%22default_rows%22%3A1%2C%22thumbnail_size%22%3A300%2C%22placeholderImgSrc%22%3A%22http%3A%5C%2F%5C%2Flocalhost%3A8888%5C%2Fproject%5C%2Fwp-content%5C%2Fuploads%5C%2F2018%5C%2F12%5C%2Fproduct-placeholder.png%22%2C%22min_height%22%3A500%2C%22default_height%22%3A500%2C%22isLargeCatalog%22%3Atrue%2C%22limitTags%22%3Afalse%2C%22hasTags%22%3Afalse%2C%22productCategories%22%3A%5B%7B%22term_id%22%3A2036%2C%22name%22%3A%22Uncategorized%22%2C%22slug%22%3A%22uncategorized%22%2C%22term_group%22%3A0%2C%22term_taxonomy_id%22%3A2036%2C%22taxonomy%22%3A%22product_cat%22%2C%22description%22%3A%22%22%2C%22parent%22%3A0%2C%22count%22%3A76%2C%22filter%22%3A%22raw%22%2C%22link%22%3A%22http%3A%5C%2F%5C%2...
    
    
Viewing 15 replies - 1 through 15 (of 15 total)
  • Like dapperchap I would also like to know what this is:
    var wc_product_block_data = JSON.parse( decodeURIComponent(

    My front page loads this data (total 312kb when saved as text file). It looks like product categories, blogs etc, does it need to be there as none of this is actually loading on the front end of this page.

    There is another thread where someone mentioned changing the code to remove this but there is no explanation of what will happen to the site if this is done.

    https://www.ads-software.com/support/topic/disable-remove-var-wc_product_block_data-json-parse-decodeuricomponent/

    Sy

    Thread Starter dapperchap

    (@dapperchap)

    Thread Starter dapperchap

    (@dapperchap)

    Thread Starter dapperchap

    (@dapperchap)

    Anyone can explain this, please?

    I have an in-development woocommerce site with 20-30K products. It was running really sluggishly. When I looked through the code the javascript block wc_product_block_data was producing literally 4.5Mb of data, incredible.

    I couldn’t find an elegant way to stop this running so for now have disabled the package directly in WooCommerce plugin.

    Go to /wp-content/plugins/woocommerce/src/Packages.php
    LINE 30 comment out
    // ‘woocommerce-blocks’ => ‘\\Automattic\\WooCommerce\\Blocks\\Package’,

    site seems to be fine without out it, obviously will need to manually redo if I update or maybe Woo will fix this.

    Same question here. It’s unbelievable how much bloat is injected into the page code.

    Thread Starter dapperchap

    (@dapperchap)

    It is odd that no one from WooCommerce team responding to this issue at all, I appreciate the freeware that we do use, but with this odd block of code, many stores with large number of products will suffer. Could someone please clarify why this is there at the first place, and what is an elegant way to remove it if not required?

    Vikram S.

    (@jodhavishalsingh)

    Hi, Use this in functions.php

    add_action('wp_footer','wooexperts_remove_block_data',0);
    add_action('admin_enqueue_scripts','wooexperts_remove_block_data',0);
    function wooexperts_remove_block_data(){ 
        remove_filter('wp_print_footer_scripts',array('Automattic\WooCommerce\Blocks\Assets','print_script_block_data'),1);
        remove_filter('admin_print_footer_scripts',array('Automattic\WooCommerce\Blocks\Assets','print_script_block_data'),1);
    }
    Thread Starter dapperchap

    (@dapperchap)

    Thank you very much @jodhavishalsingh it worked!
    Now there is another one called “wc_country_select_params” which adds a huge amount of code for country and their states selection on every single page where it is not even needed! Any idea how to get rid of that too?

    Vikram S.

    (@jodhavishalsingh)

    Hi @dapperchap , i see “wc_country_select_params” only on checkout page, i’m not getting it on all pages.

    Thanks

    Thread Starter dapperchap

    (@dapperchap)

    @jodhavishalsingh thank you, I sadly get that on all the pages, maybe because of mini-cart? Need to dig deeper to see what is causing that wanted list to appear on other pages but the cart page

    Vikram S.

    (@jodhavishalsingh)

    @dapperchap no it’s not because of mini cart, it’s used in checkout country and state filed, so that should only be there on checkout page, but if you are getting on all pages then it’s something wrong with your code.

    Thanks

    I would also like to know what this blob of data is doing there. Anyone? Anything?

    dailce

    (@dailce)

    Bump. Why is it there. I removed it using

    add_action(‘wp_footer’,’wooexperts_remove_block_data’,0);
    add_action(‘admin_enqueue_scripts’,’wooexperts_remove_block_data’,0);
    function wooexperts_remove_block_data(){
    remove_filter(‘wp_print_footer_scripts’,array(‘Automattic\WooCommerce\Blocks\Assets’,’print_script_block_data’),1);
    remove_filter(‘admin_print_footer_scripts’,array(‘Automattic\WooCommerce\Blocks\Assets’,’print_script_block_data’),1);
    }

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Howdy!

    Refactored here: https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/903 and addressed in WP 5.3

    I’m going to go ahead and mark this thread as resolved. If you have any other questions please start a new thread.

    Cheers!

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘What is wc_product_block_data?’ is closed to new replies.