CodeNewbie Community

jibahaw
jibahaw

Posted on

How To Fix Defer Parsing Of JavaScript In WordPress

Why Should You Defer Parsing of JavaScript?

When you open a website, your browser will receive the site’s content from the server and loads the code from top to bottom. However, if it finds JavaScript, the loading process will be interrupted until it finishes downloading all the JavaScript.

To solve this issue, you can defer parsing of JavaScript, which allows the browser to load the full content without waiting for the scripts to load. By implementing this task, JavaScript parsing won’t negatively affect your website’s loading time.

How to Defer Parsing of JavaScript in WordPress?

This section will show you a step-by-step guide to defer parsing of JavaScript. To top it off, we’ll also show you how to analyze the problem and test the changes after applying the task.

Analyze the site

To find out whether you should defer parsing of JavaScript in your WordPress website, analyze it using site speed testing tools like GTMetrix. As an example, here is the performance result of a website before implementing the method.
It shows that there’s an issue regarding JavaScript parsing, which means the website site needs to defer it.

Defer Parsing of JavaScript Without plugin (Only For WordPress users)

For that, you need to log in to your wp-admin. Then click over appearance then theme editor. Inside that find the Function.php file and paste the following code

function defer_parsing_of_js ( $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 );

Reference Blog
How To Fix Defer Parsing Of JavaScript In WordPress

Discussion (0)