Assets loading on every page (regardless of block used or not)
-
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
andultimate-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?
- The topic ‘Assets loading on every page (regardless of block used or not)’ is closed to new replies.