techinfoBiT
  • News
  • Startups
  • Tech
    • Internet
    • Security
  • WebMaster
    • All
    • SEO
    • Server & Hosting
    • Tools
    • WordPress
    'Sorry, This File Type Is Not Permitted for Security Reasons' How To Fix This Error in WordPress Website Development-techinfoBiT

    ‘Sorry, This File Type Is Not Permitted for Security Reasons’ How To Fix This Error in WordPress

    What is DMARC Record in DNS and Why It is Important For Email Security-techinfoBiT

    What is DMARC Record in DNS and Why It is Important For Email Security?

    How To Generate SHA-256 Hash From the Command Line on Ubuntu Server - techinfoBiT-SHA-256,Ubuntu Server, Server Solution, Linux Hashing, File Integrity, Cryptographic Hash, sha256sum, Hash Generation

    How To Generate SHA-256 Hash From the Command Line on Ubuntu Server

    Cloudflare To Deprecate Auto Minify Feature On August 5, 2024 - techinfoBiT

    Cloudflare To Deprecate Auto Minify Feature On August 5, 2024

    What is Google Analytics 4 and How to Setup GA4 for Websites - techinfoBiT

    What is Google Analytics 4 and How to Setup GA4 for Websites?

    How To Use Multiple SPF Records In A Domain | Merge Multiple SPF Easily - techinfoBiT

    How To Use Multiple SPF Records In A Domain | Merge Multiple SPF Easily

  • Science Space
  • Gadgets
    • Laptop & PCs
    • Mobile Phones
    • Wearables
  • More
    • How-To Guides
    • Reviews
    • Telecom
    • Applications
    • Press Release
No Result
View All Result
Services
techinfoBiT
  • News
  • Startups
  • Tech
    • Internet
    • Security
  • WebMaster
    • All
    • SEO
    • Server & Hosting
    • Tools
    • WordPress
    'Sorry, This File Type Is Not Permitted for Security Reasons' How To Fix This Error in WordPress Website Development-techinfoBiT

    ‘Sorry, This File Type Is Not Permitted for Security Reasons’ How To Fix This Error in WordPress

    What is DMARC Record in DNS and Why It is Important For Email Security-techinfoBiT

    What is DMARC Record in DNS and Why It is Important For Email Security?

    How To Generate SHA-256 Hash From the Command Line on Ubuntu Server - techinfoBiT-SHA-256,Ubuntu Server, Server Solution, Linux Hashing, File Integrity, Cryptographic Hash, sha256sum, Hash Generation

    How To Generate SHA-256 Hash From the Command Line on Ubuntu Server

    Cloudflare To Deprecate Auto Minify Feature On August 5, 2024 - techinfoBiT

    Cloudflare To Deprecate Auto Minify Feature On August 5, 2024

    What is Google Analytics 4 and How to Setup GA4 for Websites - techinfoBiT

    What is Google Analytics 4 and How to Setup GA4 for Websites?

    How To Use Multiple SPF Records In A Domain | Merge Multiple SPF Easily - techinfoBiT

    How To Use Multiple SPF Records In A Domain | Merge Multiple SPF Easily

  • Science Space
  • Gadgets
    • Laptop & PCs
    • Mobile Phones
    • Wearables
  • More
    • How-To Guides
    • Reviews
    • Telecom
    • Applications
    • Press Release
No Result
View All Result
techinfoBiT

How To Defer Parsing of JavaScript in WordPress for Faster Initial Loading

Nishant Kumar by Nishant Kumar
December 27, 2018
Reading Time: 8 mins read
Share on FacebookShare on Twitter > XShare via WhatsAppShare on LinkedIn

After publishing a quick article about Leverage Browser Caching to Improve Site Speed of WordPress Sites, we have been getting queries about the How To Defer Parsing of JavaScript in WordPress both of these topics are important and necessary tweak for the SEO and website performance point of view.

In this post, I am going to guide you to Defer Parsing of JavaScript in WordPress for Faster Initial Loading, I have drafted this post considering that most of the readers for this post will be beginner WordPress users, webmasters, and bloggers.

You might also like

Ubuntu Server How To Find Largest File In Directory Recursively - techinfoBiT

Ubuntu Server: How To Find Largest File In Directory Recursively

March 24, 2025
Buying an Affordable & High-Performance VPS or Web Hosting-Best VPS Offer-Hostinger-techinfoBiT Blog For-Best WordPress Hosting

Buying an Affordable & High-Performance VPS or Web Hosting

March 9, 2025

This exercise is very important for the UI and UX point of view, this can directly increase your page website’s loading speed, performance, user experience, and ultimately it will help your site rank better on the search results.

Basic Tools Needed: Firebug and Google Page Speed

Use the latest version of the Firefox web browser, download and install Firebug.

Once you get Firebug working, you need to download and install Google Page Speed add-on for Firebug. Make sure to select the “Page Speed Extension for Firefox”.

Restart your Firefox browser and go to your WordPress blog. Perform the following steps below:

  • Select any of your WordPress posts and let load it completely.
  • In your Firefox browser, go to “Developer Option > Firebug > Go to “Page Speed” tab and click “Analyze Performance”. Google Page Speed will start analyzing the current page.
  • You should see an issue reported as “Defer Parsing of JavaScript”. Expand that one; it should look similar to this:

How To Defer Parsing of JavaScript in WordPress for Faster Initial Loading

The data shows that 863Kb of javascript parsed during initial page loading which means browser needs to download that much JavaScript every time user request for that page. This will increase page size and loading time as well. Examples of JavaScript as reported in the Page Speed report are Facebook Like Widget, Facebook like button javascript, etc.

Here we will have to use a combination of Firebug and Google Page Speed to assess the improvement after you have deferred the parsing of JavaScript. The goal is to optimize the javascript to the minimum possible volume/size.

How to Enable jQuery in WordPress?

We are going to use the jQuery library to defer the parsing of JavaScript on WordPress blog/site. So take a backup of entire WordPress site data and database and then update the WordPress core, plugin templates etc; recent WordPress versions have inbuilt jQuery libraries hence update is necessary.

This will be used by your themes and your plug-ins. The path to the jQuery library in WordPress is (as of WordPress 3.3): /wp-includes/js/jquery/jquery.js?ver=1.7.1

To check if your WordPress blog already loaded jQuery, follow the steps below:

  • Go to any of your WordPress posts and load them completely in the browser.
  • View the page source code of that post.
  • If your themes already loaded the jQuery library, you should see the path to the library: /js/jquery/jquery.js?ver=1.7.1

In most cases, it will show in the head section if you are logged in as administrator or it will show somewhere in the footer if you are not logged in. Also, it will be loaded by some of the plug-ins and currently used themes.

If you do not see the path, you need to enable jQuery by following the steps below:

  • Login as administrator to your WordPress blog. Access website backend using some FTP or SSH client or from the cPanel’s file manager.
  • Find the header.php file of your theme and add the following PHP source code just before </head>
<?php wp_enqueue_script('jquery'); ?>
  • Save the changes.
  • If you are using any cache solutions such as WP Super Cache or Quick Cache then clear the cache and load the page again.
  • Load any of your WordPress posts again and view the page source; you should now be able to see the path to your jQuery library in wp-includes.

Defer Parsing of Facebook Like Widget and Like Button

Facebook Like Widget and Like Button is one of the most common culprits so let’s take of an example of Facebook Widget/Button and fix this. These widgets depend on the JavaScript hosted on Facebook. It actually slows down the loading of the page because these elements can be heavy at times.

Please do not forget to take backup of the entire website and its database before moving any further.

  • Get the actual code of Facebook Like box widget and Like Button used by your WordPress blog, for example,

Facebook Like Box example code:

<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
<fb:like-box href="https://www.facebook.com/techinfoBiT/" width="278" show_faces="true" stream="false" header="true"></fb:like-box>
Facebook Like Button example code:

<iframe src="http://www.facebook.com/plugins/like.php?href=<?php urlencode(the_permalink());?>&amp;layout=standard&amp;show_faces=false&amp;width=385&amp;action=recommend&amp;font=verdana&amp;colorscheme=light&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:385px; height:35px;" allowTransparency="true"></iframe>
  • Define a new JavaScript global object that can be used for jQuery exclusively for your deferred applications. This will avoid any conflicts with the use of jQuery for your other plugins and themes. Also since this deferred element would now be placed outside the WordPress loop, you need to define a variable for retrieving the permalink URLs.
<?php
//Retrieve post ID for retrieving permalink URL
global $wp_query;
$thePostID = $wp_query->post->ID;
?>
<script type="text/javascript">
$myjQueryvariable = jQuery.noConflict();
</script>
  • Place the code after:
<?php wp_footer(); ?>

In your templates.

  • Define the jQuery syntax for deferring the Facebook like box and button. This is the complete working jQuery code:
<script type="text/javascript"> $myjQueryvariable(document).ready(function() { $myjQueryvariable(‘#deferfacebooklikebox’).append(‘<fb:like-box href=”http://www.facebook.com/pages/php-developerorg/148874655176387/” width=”278″ show_faces=”true” stream=”false” header=”true”></fb:like-box>’); $myjQueryvariable(‘#deferfacebooklikebutton’).append(‘<iframe src=”http://www.facebook.com/plugins/like.php?href=<?php echo urlencode(get_permalink($thePostID));?>&amp;layout=standard&amp;show_faces=false&amp;width=385&amp;action=recommend&amp;font=verdana&amp;colorscheme=light&amp;height=35″ scrolling=”no” frameborder=”0″ style=”border:none; overflow:hidden; width:385px; height:35px;” allowTransparency=”true”></iframe>’); jQuery.getScript(‘http://connect.facebook.net/en_US/all.js#xfbml=1′, function() {FB.init({status: true, cookie: true, xfbml:true});});}); </script>
  • Place above jQuery code just after:
<?php
//Retrieve post ID for retrieving permalink URL
global $wp_query;
$thePostID = $wp_query->post->ID;
?>
<script type="text/javascript">
$myjQueryvariable = jQuery.noConflict();
</script>
  • Screenshot of the above code implemented:

  • Replace the old Facebook like box code and button with a div id referencing to your jQuery code. For example:
<div id="fb-root"></div> <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
<fb:like-box href="https://www.facebook.com/techinfoBiT/" width="278" show_faces="true" stream="false" header="true"></fb:like-box>
  • Replace the above code simply with:
<div id="fb-root"></div>
<div id="deferfacebooklikebox"></div>
  • “deferfacebooklikebox” is the div id used by your jQuery code to identify with the Facebook Like Widget.
  • Then for the Facebook like button, replace:
<iframe src="http://www.facebook.com/plugins/like.php?href=<?php urlencode(the_permalink());?>&amp;layout=standard&amp;show_faces=false&amp;width=385&amp;action=recommend&amp;font=verdana&amp;colorscheme=light&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:385px; height:35px;" allowTransparency="true"></iframe>

With,

<div id="deferfacebooklikebutton"></div>
  • Where “deferfacebooklikebutton” is the div id used by your jQuery code to identify with the Facebook like button.
  • Save all changes then clear the cache of your WordPress blog (in case you are using any cache solutions).
  • Now go to your website and reload or open the same page which was showing 862KB of javascript data and run Google Page Speed again. Take note how much improvement was made.

Based on the results, the amount of JavaScript during the initial page load was reduced from 862.3kB to 281.7kB after deferring Facebook Like widget and Like button. This could be reduced further if other JavaScript elements are deferred also.

But if you are using the Google Ad Sense the do not try to do this for that because doing so is against the terms and conditions of Google Ad Sense.


Tags: Apps/WebAppsDefer Parsing of JavaScriptFacebook Like BoxFacebook Like ButtonFacebook WidgetGoogle Ad SenseGoogle Page SpeedOptimize JavascriptServerWebMasterWordPress
ShareTweetSendShare
Previous Post

How to Remove mcagent.exe from Notification Area Icons

Next Post

Samsung Rolling Out Android 4.1 Jellybean Update To Galaxy S III

Nishant Kumar

Nishant Kumar

Nishant is a passionate tech blogger and has been writing about technology since 2007. His insatiable love for gadgets has made him closely follow the advancements & innovations our society has made in terms of technology since a long while now. Nishant is a highly sought after reviewer with many manufacturers requesting his opinions about their products. He covers Mobile Phones, Gadgets, Tools and all kind of tech products to give consumers Genuine Reviews, Buying Guides and reliable news.

Related Articles

Ubuntu Server How To Find Largest File In Directory Recursively - techinfoBiT

Ubuntu Server: How To Find Largest File In Directory Recursively

by Nishant Kumar
March 24, 2025
0

When managing an Ubuntu Server, disk space can quickly become an issue, especially if large files accumulate unnoticed. If you need to identify the biggest file within a directory (including...

Buying an Affordable & High-Performance VPS or Web Hosting-Best VPS Offer-Hostinger-techinfoBiT Blog For-Best WordPress Hosting

Buying an Affordable & High-Performance VPS or Web Hosting

by Nishant Kumar
March 9, 2025
0

The Virtual Private Server (VPS) is now becoming a mainstream and popular hosting option for all kinds of websites and applications. The market share of Virtual Private Servers (VPS) has...

HowTo Fix Bluetooth Connection Issue in Ford EcoSport SYNC Audio-techinfoBiT

HowTo Fix Bluetooth Connection Issue in Ford EcoSport SYNC Audio

by Suyash Anand
February 28, 2025
0

The Ford EcoSport has always been a fun-to-drive vehicle, offering a feature-packed experience that many competitors struggle to match. Unfortunately, Ford has exited the Indian market, leaving many Ford owners...

'Sorry, This File Type Is Not Permitted for Security Reasons' How To Fix This Error in WordPress Website Development-techinfoBiT

‘Sorry, This File Type Is Not Permitted for Security Reasons’ How To Fix This Error in WordPress

by techinfoBiT
October 18, 2024
0

WordPress is the most popular platform for building cost-effective, high-performance websites for all business needs. It is one of the most used platforms for building websites;  As of 2023, more...

Load More
Next Post
Samsung Rolling Out Android 4.1 Jellybean Update To Galaxy S III - techinfoBiT

Samsung Rolling Out Android 4.1 Jellybean Update To Galaxy S III

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.

techinfoBiT | Startup & Tech News, Reviews | WebMaster, How-To Guides-Tech Blog-Startup Blog India

techinfoBiT is your go-to source for the latest startup & tech news, technology reviews; WebMaster, SEO tips and how-to guides to help you stay updated and navigate the digital world know more

  • About
  • Contacts
  • Disclaimer
  • Privacy Policy

© 2012-2025 techinfoBiT | All Rights Reserved

No Result
View All Result
  • News
  • Startups
  • Tech
  • WebMaster
  • Gadgets
  • How-To Guides
  • Science Space
  • Services

© 2012-2025 techinfoBiT | All Rights Reserved