Support » Plugin: Category Icon » Unnecessary script loading on all admin pages

  • Hey!

    I was speed testing our application today and found that your plugin load its assets on all admin pages no matter if it’s required.

    We are running our application for a team with a variety of capabilities and bandwidth.
    Therefore your plugin is wasting bandwidth and slows down the admin interface.

    Would love to see a check with in the enqueue_admin_scripts() method if the assets should be loaded. At least just load them on the options screen and terms add and edit views. Like:

    function enqueue_admin_scripts () {
    	// Get current view
    	$current_screen = get_current_screen();
    	// Check if assets are needed
    	switch ( $current_screen->base ) {
    		case 'term':
    		case 'edit-tags':
    		case 'settings_page_category-icon':
    			wp_enqueue_style( $this->plugin_slug . '-admin-style', plugins_url( 'assets/css/category-icon.css', __FILE__ ), array(), $this->version );
    			wp_enqueue_script( $this->plugin_slug . '-admin-script', plugins_url( 'assets/js/category-icon.js', __FILE__ ), array( 'jquery' ), $this->version );
    			wp_localize_script( $this->plugin_slug . '-admin-script', 'locals', array(
    				'ajax_url' => admin_url( 'admin-ajax.php' )
    			) );

    If you want you could also check if the current taxonomy needs it. Would be even sleeker 😉


  • The topic ‘Unnecessary script loading on all admin pages’ is closed to new replies.