I am developing a site www.brunchear.com I have tested it

I am developing a site http://www.brunchear.com

I have tested it in gtmetrix and i have a lot of javascript during initial load. I want to load it maybe in the footer.

I use this function to load javascript.

What do yo recommend to me?

function reedwan_register_js() {

if (!is_admin()) {

wp_register_script(‘jqueryUI’, get_template_directory_uri().’/js/jquery-ui.js’, array(“jquery”:wink:, true );

wp_register_script(‘RoyalSlider’, get_template_directory_uri().’/js/jquery.royalslider.min.js’, array(“jquery”:wink:, true );

//wp_register_script(‘RoyalSlider’, get_template_directory_uri().’/js/combinado.js’, array(“jquery”:wink:, true );

wp_register_script(‘FlexSlider’, get_template_directory_uri().’/js/jquery.flexslider-min.js’, array(“jquery”:wink:, true );

wp_register_script(‘NewsTicker’, get_template_directory_uri().’/js/newsticker.jquery.min.js’, array(“jquery”:wink:, true );

wp_register_script(‘backstretch’, get_template_directory_uri().’/js/jquery.backstretch.min.js’, array(“jquery”:wink:, true );

wp_register_script(‘tabber’, get_template_directory_uri().’/’, ‘js/tabber.js’, array(“jquery”:wink:, true );

wp_register_script(‘prettyPhoto’, get_template_directory_uri().’/js/jquery.prettyPhoto.js’, array(“jquery”:wink:, true );

wp_register_script(‘ScrollTop’, get_template_directory_uri().’/js/scrolltopcontrol.js’, array(“jquery”:wink:, true );

wp_register_script(‘Custom’, get_template_directory_uri().’/js/custom.js’, array(“jquery”:wink:, true);

wp_register_script(‘hoverintent’, get_template_directory_uri() . ‘/js/hoverIntent.js’:wink:;

wp_register_script(‘superfish’, get_template_directory_uri() . ‘/js/superfish.js’, array( ‘jquery’, ‘hoverintent’ ));

wp_register_script(‘supersubs’, get_template_directory_uri() . ‘/js/supersubs.js’, array( ‘superfish’, true ));

wp_enqueue_script(‘supersubs’:wink:;

wp_enqueue_script(‘jqueryUI’:wink:;

wp_enqueue_script(‘RoyalSlider’:wink:;

wp_enqueue_script(‘FlexSlider’:wink:;

wp_enqueue_script(‘NewsTicker’:wink:;

wp_enqueue_script(‘backstretch’:wink:;

wp_enqueue_script(‘prettyPhoto’:wink:;

wp_enqueue_script(‘ScrollTop’:wink:;

wp_enqueue_script(‘Custom’:wink:;

}

}

add_action(‘init’, ‘reedwan_register_js’:wink:;

  • aristath
    • Recruit

    Hello there @estudio, I hope you’re well today!

    The wp_register_script function has a syntax like this:

    wp_register_script( $handle, $src, $deps, $ver, $in_footer );

    So in your case, you have this code:

    wp_register_script('jqueryUI', get_template_directory_uri().'/js/jquery-ui.js', array("jquery"), true );

    That means that your arguments are as follows:

    handle: jqueryUI

    source : get_template_directory_uri().’/js/jquery-ui.js’

    dependencies: array(“jquery”:wink:

    version: true

    The problem there is that “version” is set to true, and footer is not specified so instead it goes to the header.

    You should use it like this:

    wp_register_script( 'jqueryUI', get_template_directory_uri().'/js/jquery-ui.js', array("jquery"), false, true );

    This sets the version to false and assigns it to the footer.

    You’ll have to modify all your scripts according to this.

    I hope that helps!

    Cheers,

    Ari.

  • estudio
    • WPMU DEV Initiate

    i have made the changes but the perfomance its the same.

    http://gtmetrix.com/reports/brunchear.com/AMrqYJnk

    Look the value of “Defer parsing of JavaScript” its 50.

    Now my code is

    wp_register_script( 'jqueryUI', get_template_directory_uri().'/js/jquery-ui.js', array("jquery"), false, true );
    wp_register_script('RoyalSlider', get_template_directory_uri().'/js/jquery.royalslider.min.js', array("jquery"), false, true );
    wp_register_script('FlexSlider', get_template_directory_uri().'/js/jquery.flexslider-min.js', array("jquery"), false, true );
    wp_register_script('NewsTicker', get_template_directory_uri().'/js/newsticker.jquery.min.js', array("jquery"), false, true );
    wp_register_script('backstretch', get_template_directory_uri().'/js/jquery.backstretch.min.js', array("jquery"), false, true );
    wp_register_script('tabber', get_template_directory_uri().'/', 'js/tabber.js', array("jquery"), false, true );
    wp_register_script('prettyPhoto', get_template_directory_uri().'/js/jquery.prettyPhoto.js', array("jquery"), false, true );
    wp_register_script('ScrollTop', get_template_directory_uri().'/js/scrolltopcontrol.js', array("jquery"), false, true );
    wp_register_script('Custom', get_template_directory_uri().'/js/custom.js', array("jquery"), false, true);

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.