Boost Up Website PageSpeed with defer parsing of JavaScript

Known:

My website is a2fahmi.com based on WordPress

Page Speed Testing:

Tested using gtmetrix.com

Question:

How to defer parsing of JavaScript … ?

Answer:

Open your wp-includes/function.php and add this code:

function defer_parsing_of_js( $url ) {
    if ( is_user_logged_in() ) return $url; //don't break WP Admin
    if ( FALSE === strpos( $url, '.js' ) ) return $url;
    if ( strpos( $url, 'jquery.js' ) ) return $url;
    return str_replace( ' src', ' defer src', $url );
}
add_filter( 'script_loader_tag', 'defer_parsing_of_js', 10 );

Result:

Re-test again using gtmetrix.com and see that the “Defer Parsing of JavaScript” Grade increase or no

Thanks for reading

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *