Why we should work on “defer parsing of JavaScript.”
Performance and speed are most important to run a website. There are many techniques to speed up your website with “Defer Parsing of JavaScript.”
But before continue, you need to understand the reason why we should work on “defer parsing of JavaScript.”
The JavaScript mostly placed between <head></head> tags. When opening a website, it always loads the code from top to bottom. If lots of JavaScript are placed in the head section, the website will take more time to load.
After “defer parsing of 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.
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 installing a small plugin “Theme editor” quickly.
Check out: How to speed up your WordPress Website using .htaccess
Don’t ever forget to keep a backup of your original file so you can back up if you found any problem on your website.
- The file “Function.php” is located in your WordPress theme directory. Go to /public_html/yourwebsite.com/wp-content/themes/active theme/function.php. Open the file, paste the code at the bottom of the “file,” and feel the magic.
Or
- 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 (Defer Parsing of JavaScript)
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 of JavaScript, I will not discuss these Plugins in detail.
- WP Deferred JavaScript
- Speed Booster Pack
- Async JavaScript