How to Solve Defer Parsing Of Javascript WordPress: Coding+Plugin

 

Have you checked the 6 best image optimizer to speed up your website? Okay this post is not about the image compressors but the long JavaScript strings which delays our page load.

Let us start to defer parsing of JavaScript which can eventually speed up our site.

 

WHAT IS DEFER PARSING OF JAVASCRIPT

In layman language parsing means breaking of a component in-to its logical and syntactic parts.

While loading a page, its browser must parse all the contents which ads to additional time to the page load. So by minimizing CSS, JS files and delaying javascript load until it is required to be implemented, we can delay the initial load time of the page.

HOW TO DEFER PARSING OF JAVASCRIPT WORDPRESS

I would recommend using this method by including some coded lines in your function.php files to defer parsing of javascript.

I always prefer using less number of plugins as they add to the initial load time of the page.

If you are not sure where to add the codes then follow the steps.

Warning! Copy the original files separately before editing function.php or htaccess. As minor mistakes can mess up your site.

1.WordPress Dashboard> Appearance> Editor

2. On the right side of the page you will find all your php files.

3. Click on Function.php > Scroll down to the end and add the following set of codes.

/* 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 );

 

 

WHAT HAPPENS WHEN WE DEFER JAVASCRIPT LOADING

Generally a JavaScript is placed in the head section and a website is loaded from top to bottom. So if we have a long string of JS to be read then websites content will take a longer time to appear as it have to wait until all the JavaScript codes are finished.

When we add codes to defer parsing of JavaScript then it instructs the browser that it does not have to wait for the entire JavaScript codes to finish, rather can display content while it is being executed. Thus it speeds up the initial load time of the website.

DEFER PARSING OF JAVASCRIPT WORDPRESS PLUGIN

If you are not comfortable with the codes then plugin is a way to play safe.

Lazy Load is a powerful plugin which loads the images while you are scrolling down the pages. Thus it would wait till the time the user can see the particular image preventing to load all the images together in a page which renders to delayed load time.

Install from WordPress Plugin> Activate

No setup required. It will start working right away.
It will make your blog way faster.

WRAPPING UP

Alright so it was about how to solve defer parsing of Javascript in WordPress. If you check the GT Metrix there are many more issues which needs to be solved. Next we will see how to remove query string from static resources.

Before checking the site speed you should empty the browser cache for better results.

Check out the all the factors which are making your webpage delay.

Leave a Reply

Logged in as admin. Log out?