Tagged: 

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #28646

    Hi, in testing my pagespeed I keep getting the note: Remove render-blocking JavaScript. How do I go about this?

    Secondly, I’m reading quite a few posts about the need to get all js loaded in the footer. How could I best get this done?

    #138212

    Hi,

    Try using this plugin.

    Regards,

    Josue

    #138213

    Thanx Josue, for your reaction. In the absence of any answers I tried cutting out the following code from my header.php and placing it under the first php code in my footer.php (May I pls know if it isn’t an appropriate maneuvre and if I will still need the:

    <?php

    /* add javascript */

    wp_enqueue_script( ‘jquery’ );

    wp_enqueue_script( ‘avia-default’ );

    wp_enqueue_script( ‘avia-prettyPhoto’ );

    wp_enqueue_script( ‘avia-html5-video’ );

    wp_enqueue_script( ‘adaptavia-slider’ );

    /* We add some JavaScript to pages with the comment form

    * to support sites with threaded comments (when in use).

    */

    if ( is_singular() && get_option( ‘thread_comments’ ) ) { wp_enqueue_script( ‘comment-reply’ ); }

    ?>

    #138214

    Hey,

    It is ok to move the code. Just place it on top of this code:

    avia_option('analytics', false, true, true);
    wp_footer();

    Do you experience any issues after doing so? If not then it should work ok.

    Regards,

    Ismael

    #138215

    Thank you….but do you mean above this code :

    <?php

    /* Always have wp_footer() just before the closing </body>

    * tag of your theme, or you will break many plugins, which

    * generally use this hook to reference JavaScript files.

    */

    avia_option(‘analytics’, false, true, true);

    wp_footer();

    ?>

    #138216

    wp_register_script allows you to print the scripts in the footer area. You don’t need to move the wp_enqueue_script code. However Kriesi already prints the scripts in the footer area (and you don’t need to take care of this) except avia.js and jquery.js. Both scripts must be in the head area or you’ll break the theme.

    That said you can also try plugins like: http://wordpress.org/plugins/w3-total-cache/ which help you to combine & compress scripts. Nevertheless you must make sure that jquery.js and avia.js scripts are called in the head section.

    #138217

    Well, as at now I really dont know which way to go….I already have w3tc optimized on my website with cloudflare and cdn77, but pls read my initial request: ‘Hi, in testing my pagespeed I keep getting the note: Remove render-blocking JavaScript. How do I go about this?

    Secondly, I’m reading quite a few posts about the need to get all js loaded in the footer. How could I best get this done?

    #138219

    Remove render-blocking JavaScript. How do I go about this?

    Secondly, I’m reading quite a few posts about the need to get all js loaded in the footer. How could I best get this done?

    That’s simple not always possible. Eg scripts like jquery.js and avia.js MUST load at the top (otherwise you’ll break the website) and it makes no sense to load them as inline js which is considered as non-blocking js (see https://developers.google.com/speed/docs/insights/BlockingJS ) because then the browser can’t cache the js files and you add 60-80kb unnecessary data to the html document. Like the article explains ( https://developers.google.com/speed/docs/insights/BlockingJS ) this makes only sense with very small scripts but not with the jquery framework script or bigger scripts like avia.js.

    These pagespeed hints are just guidelines and it’s not always the best practice or reasonable to follow them.

    #138220

    Thank you so much for that calrification…..so how about removing query strings from static files. I learnt that I could add this code to functions.php but I dont know if thats wise and where to add it exactly:

    /** Remove Query strings from Static Resources. */

    function _remove_script_version( $src ){

    $parts = explode( ‘?’, $src );

    return $parts[0];

    }

    add_filter( ‘script_loader_src’, ‘_remove_script_version’, 15, 1 );

    add_filter( ‘style_loader_src’, ‘_remove_script_version’, 15, 1 );

    #138221

    You can add this code to the very bottom of the theme functions.php file. The query var helps the browser to delete outdated script versions from the cache. If you update the script from i.e. 1.0 to v1.5 the query var will also change and eventually the entire url changes. This forces the browser to re-download the latest version of the script. If you don’t update your website often this query var is not required, otherwise I’d stick with the default wordpress enqueue function which outputs this query var.

Viewing 10 posts - 1 through 10 (of 10 total)

The topic ‘moving javascript to footer’ is closed to new replies.