How to Defer Parsing of JavaScript in Avada?

Estimated read time 1 min read

To defer parsing of JavaScript in Avada, you can add the following code to your Avada theme’s functions.php file:

function defer_parsing_of_js ( $url ) {
    if ( is_user_logged_in() ) return $url;
    if ( FALSE === strpos( $url, '.js' ) ) return $url;
    if ( strpos( $url, 'jquery.js' ) ) return $url;
    return "$url' defer ";
}
add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );

This code will defer parsing of all JavaScript files except for jquery.js, which is a critical component for the proper functioning of Avada.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply