Where do you recommend loading in your jQuery library on WordPress site?

Where is the best place for performance to load in the jQUery library on a WordPress site? header.php? footer.php? Thanks

Related posts

Leave a Reply

2 comments

  1. YSlow recommendations would say the footer is the best place if you can manage it, because the JavaScript won’t delay loading the page. Put all your JavaScript just before the </body> tag. Minify all of them and combine as many as possible to minimize downloads.

  2. You can load jQuery in either place, but ideally you want to use WordPress’ built-in function for adding scripts, including jQuery which they already have setup to do. It also allows you to include code in either the header or footer before the closing </body> tag.

    http://codex.wordpress.org/Function_Reference/wp_enqueue_script

    Example, put this in your functions.php file and it will de-register the currently included copy of jQuery in WordPress and include the latest version hosted by Google’s CDN:

    <?php
        function my_init_method() {
        wp_deregister_script( 'jquery' );
        wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js', false, '1.6', true);
        wp_enqueue_script( 'jquery' );
    }    
    
    add_action('init', 'my_init_method');
    ?>
    

    EDIT: The code example above sets the last argument to “true” which will place jQuery in the footer.