Support » Plugin: Ultimate Blocks - Gutenberg Blocks Plugin » Assets loading on every page (regardless of block used or not)

  • Resolved Will Stocks


    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. 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() )
    		wp_deregister_style('ultimate-blocks'); //can this just be dequeued entirely?
    		wp_deregister_script('ultimate-blocks'); //can this just be dequeued entirely?
    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' );


    function remove_unnecessary_flickity() {
    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



    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.


    Thread Starter Will Stocks


    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);


    add_action('wp_footer', function(){
        $ultimateblockExists = $this->ultimateblock !== null && $this->ultimateblock->hasContent();
        if ($ultimateblockExists === true){
    }, 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


    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.


    Thread Starter Will Stocks


    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.