• Resolved cjyabraham

    (@cjyabraham)


    Hi,
    Would it be possible to only include the UM css/js files on pages that need them? I count 38 css/js files in total that are included on every page of my site even though most of my site doesn’t need them. It’s a big load and slows down the experience unnecessarily. Any thoughts on including this by default in the plugin?

    I may also write a patch to do this in the meantime.

    Thanks,
    Chris

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter cjyabraham

    (@cjyabraham)

    Here’s the code for anyone who’s interested:

    
    // improve performance by deregistering ultimate member css/js on pages 
    // that don't need them
    add_action( 'wp_print_scripts', 'my_deregister_ultimate_member_javascript', 100 );
    add_action( 'wp_print_styles', 'my_deregister_ultimate_member_styles', 100 );
    
    function on_ultimate_member_page() {
    	$um_option = get_option( 'um_options' );
    
    	if ( !$um_option ) {
    		return false;
    	}
    
    	$um_page = array( $um_option['core_user'], 
    					$um_option['core_login'], 
    					$um_option['core_register'], 
    					$um_option['core_members'], 
    					$um_option['core_logout'], 
    					$um_option['core_account'], 
    					$um_option['core_password-reset'] 
    				);
    
    	if ( is_page( $um_page ) ) {
    		return true;
    	} else {
    		return false;
    	}
    }
    
    function my_deregister_ultimate_member_styles() {
    	if ( on_ultimate_member_page() ) 
    		return;
    
    	wp_deregister_style( 'um_fonticons_ii' );
    	wp_deregister_style( 'um_fonticons_fa' );
    	wp_deregister_style( 'um_crop' );
    	wp_deregister_style( 'um_tipsy' );
    	wp_deregister_style( 'um_raty' );
    	wp_deregister_style( 'select2' );
    	wp_deregister_style( 'um_fileupload' );
    	wp_deregister_style( 'um_datetime' );
    	wp_deregister_style( 'um_datetime_date' );
    	wp_deregister_style( 'um_datetime_time' );
    	wp_deregister_style( 'um_scrollbar' );
    	wp_deregister_style( 'um_rtl' );
    	wp_deregister_style( 'um_default_css' );
    	wp_deregister_style( 'um_modal' );
    	wp_deregister_style( 'um_responsive' );
    	wp_deregister_style( 'um_styles' );
    	wp_deregister_style( 'um_members' );
    	wp_deregister_style( 'um_profile' );
    	wp_deregister_style( 'um_account' );
    	wp_deregister_style( 'um_account' );
    	wp_deregister_style( 'um_old_css' );
    }
    
    function my_deregister_ultimate_member_javascript() {
    	if ( on_ultimate_member_page() ) 
    		return;
    
    	wp_deregister_script( 'select2' );
    	wp_deregister_script( 'um_scrollbar' );
    	wp_deregister_script( 'um_jquery_form' );
    	wp_deregister_script( 'um_fileupload' );
    	wp_deregister_script( 'um_datetime' );
    	wp_deregister_script( 'um_datetime_date' );
    	wp_deregister_script( 'um_datetime_time' );
    	wp_deregister_script( 'um_datetime_legacy' );
    	wp_deregister_script( 'um_datetime_locale' );
    	wp_deregister_script( 'um_tipsy' );
    	wp_deregister_script( 'um_raty' );
    	wp_deregister_script( 'um_crop' );
    	wp_deregister_script( 'um_modal' );
    	wp_deregister_script( 'um_responsive' );
    	wp_deregister_script( 'um_functions' );
    	wp_deregister_script( 'um-gdpr' );
    	wp_deregister_script( 'um_conditional' );
    	wp_deregister_script( 'um_scripts' );
    	wp_deregister_script( 'um_members' );
    	wp_deregister_script( 'um_profile' );
    	wp_deregister_script( 'um_account' );
    	wp_deregister_script( 'um_gchart' );
    }

    I added this to my subtheme’s functions.php and it improves page speed and scoring a lot. Thank you. This, along with combining and minifying all the css and js would be a good addition to the core plugin.

    • This reply was modified 5 years, 9 months ago by dmcknight.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘conditional inclusion of css/js files’ is closed to new replies.