How to defer parsing of JavaScript in WordPress – Guide

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

Performance and speed are most important to run a website. There are many techniques through which you can 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 there are lots of JavaScript are place 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 install a small plugin “Theme editor” for a short time.

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.

  1. 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 and paste the code at the bottom of the “file,” and then feel the magic.


  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 (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, so I will not discuss these Plugins in detail.

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

Related Articles

Latest Articles