Loading Genesis Responsive Slider conditionally?

Homepage Community Forums Vintage Theme Support Loading Genesis Responsive Slider conditionally?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #18509
    Matthew
    Customer

      Hello,

      While optimizing the theme for speed, I noticed genesis slider loads in every page even though we only use it for the homepage.

      To make the user experience more enjoyable (and get a better Google Pagespeed ranking), I thought it might be good dequeue’ing the js and stylesheet of the slidershow to only load in the homepage.

      This is the code I have so far, but it doesn’t seem to be working;

      // Dequeue css and js for Genesis Slider
      function my_dequeue_styles() {
      	wp_dequeue_style( 'slider_styles' );
      }
      	 
      function my_dequeue_javascript() {
      	wp_dequeue_script( 'flexslider' );
      
      }
      
      // Conditionally load css and js for Genesis Slider
      function my_enqueue_style() {
        	if( is_front_page() ) {
      	    wp_enqueue_style( 'slider_styles', false ); 
      	}
      }
      
      function my_enqueue_script() {
          if( is_front_page() ) {
      	    wp_enqueue_script( 'flexslider', true );
      	}
      }
      
      add_action( 'wp_enqueue_scripts', 'my_enqueue_style' );
      add_action( 'wp_enqueue_scripts', 'my_enqueue_script' );

      Can you spot anything that I might have missed?

      Cheers

      #18534
      Wes
      Moderator

        Oh wow I didn’t know it loads on every page…..(maybe I have in the past but forgot since it’s been a while). I just checked the demos on the sites that I’m using it on and I’m just now noticing it showing up in the code. I’ll have to investigate to see how to get it to work on just one specific page.

        If I don’t find anything, then I’ll probably need to reach out to the Devs to see if they have a quick way to do it.

        #18544
        Matthew
        Customer

          Yeah, I remember disabling Genesis slideshow on my website a few years ago as I was having the same issue. Small extra files like that really make a different for overall site performance and user experience.

          I’m a bit of fickler for performance and speed after my experience of optimizing my sites speed down to a 1.5 second load time and going from 5k unique hits per month to 20k and ranking for a few dozen terms.

          Do you think the code above might work if written properly? I based it on Justin’s article: http://justintadlock.com/archives/2009/08/06/how-to-disable-scripts-and-styles and I know I’m probably missing just a silly detail.

          I look forward to seeing what you find.

          #18617
          Wes
          Moderator

            I’m not sure if it will work or not. To be honest, this could get answered much faster by contacting the Developers/Creators of this Plugin to see if they have a better solution. Since I haven’t created the plugin, I’d highly recommend contacting the Plugin Developer to see if they have a shortcut/way to get this working. I don’t want to lead you down the wrong path with the wrong solution 馃檪

            Let them know what you’re trying to do, and they should have a solution for it. I assume this question has been asked before, so let’s hope there’s a way!

          Viewing 4 posts - 1 through 4 (of 4 total)
          • You must be logged in to reply to this topic.