Performance and speed are most import to run a website. There are many techniques through which you can speed up your website, and one, which is most import is “Defer Parsing of JavaScript”.

How to Defer Parsing of JavaScript in WordPress

You May Also Like:- How to speed up your WordPress Website using .htaccess

But before continue, you need to understand the reason why we should work on “defer parsing JavaScript”.

The JavaScript mostly placed between <head></head> tags. When opening a website, it always loads the code from top to bottom. If there are lots of JavaScript are place in the head section, the website will take more time to load.

After “defer parsing JavaScript” the website will not wait for JavaScript codes to load. That means the website will load quickly.

After implementing the Steps below you will find the results like this or Maybe much improved.

JavaScript

 

There are too many Plugins that can do the same job. But I will recommend Deferring parsing JavaScript by placing a code in the function.php file.

You can do this by accessing the function.php file using FTP or simply install a small plugin “Theme editor” for a short time.

Don’t ever forget to keep a backup of your original file so you can back up if you found any problem in your website.

  1. The file “Function.php” is located in your WordPress theme directory. Simply go to /public_html/yourwebsite.com/wp-content/themes/active theme/function.php. Open the file and past the code at the bottom of the file and then feel the magic.

Or

  1. Install “Theme Editor”

Go to settings>>Theme Editor>>Your active theme>>function.php

Add the code at the bottom of the file. Save and enjoy

 

The 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 );

Test your website again and feel the difference. You can uninstall the “Theme Editor” Plugin after completing this job.

There are some plugins that you can also try for the same job. But as I am not recommending any plugin to “defer Parsing JavaScript” so I will not discuss these Plugins in detail.

  1. WP Deferred JavaScript
  2. Speed Booster Pack
  3. Async JavaScript

 

Thanks for Reading.