jmccole83
5/15/2018 - 7:50 PM

Defer Parsing of JavaScript

Add the below snippet to defer parsing of javascript, remember to test any scripts to ensure they work correctly.

/**
 * Defer parsing of javascript.
 */
if (!(is_admin() )) {
    function defer_parsing_of_js ( $url ) {
        if ( FALSE === strpos( $url, '.js' ) ) return $url;
        if ( strpos( $url, 'jquery.js' ) ) return $url;
        // return "$url' defer ";
        return "$url' defer onload='";
    }
    add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );
}