• Resolved Will Stocks

    (@willstockstech)


    Hi guys,
    I noticed today that UB assets are being loaded on every single page (including flickity – I’ve toggled image slider off!) which is bloating pages unnecessarily and causing extra requests.

    blocks.style.build.css contains the CSS for every single block – even those that I’ve toggled off, resulting in a lot of unused CSS and unnecessary bloat.

    ultimate-blocks-public.css and ultimate-blocks-public.js are both empty, so that’s two wasted requests ??

    I’ve gotten around this temporarily by implementing the following (which works for my use-case – appreciate not everyone’s!):

    function custom_script_conditional_loading() {
    	if( ! is_single() )
    	{
    		//ULTIMATE BLOCKS
    		wp_deregister_style('ultimate-blocks'); //can this just be dequeued entirely?
    		wp_deregister_script('ultimate-blocks'); //can this just be dequeued entirely?
    		wp_deregister_style('ultimate_blocks-cgb-style-css');
    		wp_deregister_script('ultimate_blocks-tabbed-content-front-script');
    		wp_deregister_script('ultimate_blocks-content-toggle-front-script');
    	}
    }
    add_action( 'wp_enqueue_scripts', 'custom_script_conditional_loading', -1 );
    add_action( 'wp_enqueue_styles', 'custom_script_conditional_loading', -1 );
    add_action( 'wp_print_styles', 'custom_script_conditional_loading' );

    and

    function remove_unnecessary_flickity() {
    	wp_deregister_script('ultimate_blocks-image-slider-front-script');
    }
    add_action( 'wp_enqueue_scripts', 'remove_unnecessary_flickity', 11 );

    Is there a better way that assets could be handled, by only invoking them when they actually need to be used?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Ultimate Blocks

    (@ultimateblocks)

    Hi,

    Thank you very much for the detailed post.

    First of all, we are sorry we didn’t handle the assets well. We are adding this to the high priority of our to-do list.

    We will improve this as soon as possible.

    Regards.

    Thread Starter Will Stocks

    (@willstockstech)

    Cheers guys – I look forward to the future (I LOVE UB so far!!)

    I’ve seen some interesting ways to handle assets, which I don’t know if is of interest to you?

    The best I’ve seen so far (from another plugin I use) is something along the lines of (this is probably semantically incorrect… but I hope you understand):

    add_filter('the_content', function($content){
        if ( in_the_loop() && is_main_query() ){
            $this->hasContent() = (strpos($content, 'UB ID or Class here') !== false);
        } 
        return $content; 
    }, 9999, 1);

    or

    add_action('wp_footer', function(){
        $ultimateblockExists = $this->ultimateblock !== null && $this->ultimateblock->hasContent();
        if ($ultimateblockExists === true){
            $this->enqueueFrontendAssets();
        }
    }, 1);

    Again, this probably is semantically incorrect, but I’m hoping it makes some sort of sense to you… basically, it’s just a “simple” check whether the current content includes a UB block or not!

    Plugin Author Ultimate Blocks

    (@ultimateblocks)

    Again, thank you very much for this.

    We are definitely looking into that.

    We are glad that you love UB so far. We are doing some more awesome stuff and we believe you will love the future iterations too.

    Regards.

    Thread Starter Will Stocks

    (@willstockstech)

    Just seen that there was recently an update for this – thanks guys!!! ?? ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Assets loading on every page (regardless of block used or not)’ is closed to new replies.