Support » Plugin: Dave's WordPress Live Search » Move scripts to wp_footer();

  • Resolved rtvenge

    (@rtvenge)


    Hello,

    Thanks for building this plugin. It works really well!

    I’m trying to get all renderblocking scripts out of the <head> per Google PageSpeed Insights. Is there a chance we could set the $in_footer param to true on the script enqueues? I just added true to the 6 enqueue functions in class-daves-wordpress-live-search.php:

    if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
      wp_enqueue_script( 'daves-wordpress-live-search', plugin_dir_url( __FILE__ ) . 'js/daves-wordpress-live-search.js', array( 'jquery' ), null, true );
      wp_enqueue_script( 'excanvas', plugin_dir_url( __FILE__ ) . 'js/excanvas.js', 'jquery', null, true );
      wp_enqueue_script( 'spinners', plugin_dir_url( __FILE__ ) . 'js/spinners.js', 'explorercanvas', null, true );
    }
    else {
      wp_enqueue_script( 'daves-wordpress-live-search', plugin_dir_url( __FILE__ ) . 'js/daves-wordpress-live-search.min.js', array( 'jquery' ), null, true );
      wp_enqueue_script( 'excanvas', plugin_dir_url( __FILE__ ) . 'js/excanvas.compiled.js', 'jquery', null, true );
      wp_enqueue_script( 'spinners', plugin_dir_url( __FILE__ ) . 'js/spinners.min.js', 'explorercanvas', null, true );
    }

    I haven’t done extensive testing on this, but let me know if you want me to. You have the dependencies set correctly, so if jquery is set in the header, it should still work correctly.

    Thanks!

    https://wordpress.org/plugins/daves-wordpress-live-search/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Dave Ross

    (@csixty4)

    That should work fine, and that’s what the new version I’m working on does.

    Thanks much for getting this in the next version!

    I was just checking up on this. I am running the latest version (4.3) and it looks like this didn’t make it in. I tried coming up with a fix myself, but it seems that underscore.js really wants jquery and jquery-migrate in the <head>. 🙁

    Any ideas?

    thanks!

    Plugin Author Dave Ross

    (@csixty4)

    That shouldn’t be the case, but I’ve run into weird dependency issues like that before too. In the “next generation” version of DWLS, I’m setting the $in_footer flag and my code works fine. I might put out a new version of DWLS that sets that flag just for a little extra performance if it got overlooked in the last update. But I agree it would be great if everything could be in the footer or even async. I’m just not sure WordPress is ready to run like that yet.

    Thanks Dave! I’ll keep an eye out for the new version.

    Yeah, I’d love to see WordPress get better at this kind of stuff. It can be a lot trickier to implement than it looks on the surface. 🙂

    Let me know if you need any help with troubleshooting or anything. I’d love to help!

    Plugin Author Dave Ross

    (@csixty4)

    Took a while to get to it, but this is done.

    Thanks a lot, Dave! I know these things seem easy on the surface but become difficult quickly.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Move scripts to wp_footer();’ is closed to new replies.