itsmeit.bizitsmeit.biz
  • Home
  • Windows
    • Windows Software
  • Ubuntu & Linux
    Ubuntu & Linux
    The top blog articles on Ubuntu and Linux, featuring valuable tips and tricks, empower you to master these operating systems and enhance your experience.
    Show More
    Top News
    How to use chmod command in Linux or Ubuntu with examples
    How to use chmod command in Linux or Ubuntu with examples
    November 11, 2023
    How to Remove Ubuntu Dual boot Windows 11 UEFI and Legacy
    How to Remove Ubuntu Dual boot Windows 11 UEFI and Legacy
    November 10, 2023
    How to install php7.4 on Ubuntu & Config php7.4-fpm - itsmeit.biz
    How to install php7.4 on Ubuntu 22.04 | 20.04 LTS
    November 10, 2023
    Latest News
    How to install Composer on Ubuntu 20.04 | 22.04 & Linux
    November 13, 2023
    How to Configure Redis Cache to Speed ​​Up WordPress Site
    November 15, 2023
    Install Ibus-bamboo or Ibus-unikey for Accented Letters on Ubuntu 22.04
    November 11, 2023
    How to install MariaDB on Ubuntu 22.04, 20.04 and Debian
    November 11, 2023
  • Web developer
    • Wordpress Theme
      • Blog News
      • Fashion Theme
      • Theme Elementor
      • WooCommerce Theme
    • Wordpress Plugin
    • Magento Developer
Reading: How to Fix Website Slowdowns Caused by Adding Facebook Social Code
Share
Font ResizerAa
itsmeit.bizitsmeit.biz
Font ResizerAa
  • Linux & Ubuntu
  • Windows
    • Tips & Trick
    • Windows Software
  • Web developer
    • Magento Developer
    • Wordpress Plugin
    • WP Blog Theme
    • WP Fashion Theme
    • WooCommerce Theme
  • Log Out
Have an existing account? Sign In
Follow US
Copyright © 2022. All Rights Reserved.
Web developer

How to Fix Website Slowdowns Caused by Adding Facebook Social Code

duyanh
Last updated: November 17, 2023
By duyanh Published November 13, 2023
Share
SHARE

Table of contents

  1. How to optimize and fix website slows down when add Facebook Social code
    1. Optimize Google speed when add code Facebook like/share
      1. The Facebook like share HTML code has been optimized:
      2. The Facebook like share JS code has been optimized:
      3. How to use insert Facebook like share code on the website
    2. Fixing slow website issues caused by Facebook comment code
    3. How to fix slows down when integrate Facebook Messenger
      1. Default code when inserting facebook messenger:
      2. Facebook messenger code after it has been optimized:

How to fix website slows down when add Facebook Social code such as FB like/share, Facebook comment, or FB chat messenger. This article by itsmeit will guide you in solving both mobile and desktop speed issues and help eliminate the website slowdown caused by using these features, thereby achieving high scores on PageSpeed Insights.

How to optimize and fix website slows down when add Facebook Social code

How to optimize and fix website slows down when add Facebook Social code

When you add a Facebook page code, chat message or like/share to a website, they send a request to the app’s feed to download and display the respective functions. This increases the initial size of the website and has to wait for Facebook JS and HTML files to be added, slowing down the website and reducing the user experience.

Optimize Google speed when add code Facebook like/share

Optimize Google speed when add code Facebook like/share

First, look at the default code with Facebook like share, it should look like this:

<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v15.0&appId=1019721838751823&autoLogAppEvents=1" nonce="rlxHIsc6"></script>
<div class="fb-page" data-href="https://www.facebook.com/itsmeit.blogs" data-tabs="events" data-width="" data-height="" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true"><blockquote cite="https://www.facebook.com/itsmeit.blogs" class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/itsmeit.blogs">itsmeit.biz</a></blockquote></div>

So how to fix website slows down when add Facebook Like/Share? Now modify the above code as follows:

The Facebook like share HTML code has been optimized:

<!-- Fix perfomance Social facebook by itsmeit -->
<div id="fb-root"></div>
<div class="fb-page" data-href="https://www.facebook.com/itsmeit.blogs" data-tabs="events" data-width="" data-height="" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true"><blockquote cite="https://www.facebook.com/itsmeit.blogs" class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/itsmeit.blogs">itsmeit.biz</a></blockquote></div>

The Facebook like share JS code has been optimized:

<!-- Fix perfomance Social facebook by itsmeit -->
<script type="application/javascript">
    window.addEventListener('load', function () {
        var is_facebook_load = 0
        window.addEventListener('scroll', function () {
            if (is_facebook_load == 0) {
                is_facebook_load = 1;
                var ele = document.createElement('script');
                ele.async = true;
                ele.defer = true;
                ele.src = 'https://connect.facebook.net/(Link social của bạn)';
                var sc = document.getElementsByTagName('script')[0];
                sc.parentNode.insertBefore(ele, sc);
            }
        }, false);
    });
</script>

How to use insert Facebook like share code on the website

If you use Wordpress, to use the code above ItsmeIT will guide you to create a shortcode, from which you can use the shortcode anywhere you want to display on the website.

Step 1: Open the functions.php file and add the following code:

Note: You need to replace appId your, display name and facebook page link.

add_shortcode('add_facebook_script_like_share', 'add_facebook_script_like_share');
function add_facebook_script_like_share()
{
    ?>
    <!-- Fix perfomance Social facebook by itsmeit -->
    <div id="fb-root"></div>
    <div class="fb-page" data-href="https://www.facebook.com/itsmeit.blogs"
        data-tabs="events" data-width=""
        data-height="" data-small-header="false"
        data-adapt-container-width="true" data-hide-cover="false"
        data-show-facepile="true">
        <blockquote cite="https://www.facebook.com/itsmeit.blogs"
            class="fb-xfbml-parse-ignore"><a
            href="https://www.facebook.com/itsmeit.blogs">itsmeit | Technology Blogs</a>
        </blockquote>
    </div>
    <script type="application/javascript">
        window.addEventListener('load', function () {
            var is_facebook_load = 0
            window.addEventListener('scroll', function () {
                if (is_facebook_load == 0) {
                    is_facebook_load = 1;
                    var ele = document.createElement('script');
                    ele.async = true;
                    ele.defer = true;
                    <!-- thay appId của bạn -->
                    ele.src = 'https://connect.facebook.net/vi_VN/sdk.js#xfbml=1&version=v15.0&appId=1019721838751823&autoLogAppEvents=1';
                    var sc = document.getElementsByTagName('script')[0];
                    sc.parentNode.insertBefore(ele, sc);
                }
            }, false);
        });
    </script>
	<?php
}

Step 2: How to using the shortcode

The above code has created us a shortcode to use in wordpress is [ add_facebook_script_like_share], now you can use it to insert anywhere you want it to appear.

Fixing slow website issues caused by Facebook comment code

Similar to the Facebook page, after you have created the comment plugin code and added it to your website, it will appear in its default form, like this:

Fixing slow website issues caused by Facebook comment code (illustration)
Fixing slow website issues caused by Facebook comment code (illustration)

Normally comments will be added after each post, now itsmeit will use a hook in wordpress with the_content function to add custom code in functions.php, the code to fix website slows down when add Facebook comment will be as follows:

add_filter('the_content', 'add_fb_comment_after_content');
function add_fb_comment_after_content($content)
{
    /** Add only after post */
    if (is_singular('post')) {
        ?>
        <div id="fb-root"></div>
        <script>
            window.addEventListener('load', function () {
                var is_fb_comment_load = 0;
                window.addEventListener('scroll', function () {
                    if (is_fb_comment_load == 0) {
                        is_fb_comment_load = 1;
                        var ele = document.createElement('script');
                        ele.crossorigin = 'anonymous';
                        ele.nonce = 'LeGWcQZO';
                        ele.src = 'https://connect.facebook.net/vi_VN/sdk.js#xfbml=1&version=v15.0&appId=1019721838751823&autoLogAppEvents=1'; /** Note: change your ele.src appId */
                        var sc = document.getElementsByTagName('script')[0];
                        sc.parentNode.insertBefore(ele, sc);
                    }
                });
            });
        </script>
        <?php
        $fb_comment_after = '<div class="fb-comments" data-href="'. get_permalink(get_the_ID()) . '" data-width="100%" data-numposts="5"></div>';
        return $content . $fb_comment_after;
    }
    return $content;
}

Save the file and clear the cache (if any) and check the facebook comment already displayed, and make sure when you test the speed, the score won’t have any error or warning from facebook social media. In addition to Facebook Social you can do the same with other Social applications.

fix website slows down when add facebook code 8

How to fix slows down when integrate Facebook Messenger

Similar to the previous two methods of addressing the issue of Facebook code slowing down website performance, the next step is to compare the default Facebook chat messenger code with the optimized version and conduct testing to evaluate the results.

Default code when inserting facebook messenger:

<!-- Messenger Plugin chat Code -->
<div id="fb-root"></div>

<!-- Your Plugin chat code -->
<div id="fb-customer-chat" class="fb-customerchat"></div>

<script>
  var chatbox = document.getElementById('fb-customer-chat');
  chatbox.setAttribute("page_id", "111009301424827");
  chatbox.setAttribute("attribution", "biz_inbox");
</script>

<!-- Your SDK code -->
<script>
window.fbAsyncInit = function()  {
  FB.init({
      xfbml            : true,
      version          : 'v15.0'
    });
  };

  (function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = 'https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js';
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));
</script>

Facebook messenger code after it has been optimized:

Note: Chat messenger will normally be placed in the bottom corner of the web page, so I used the function wp_footerto display it at the bottom. Open the functions.php file in your theme and add this code to fix slows down when integrate Facebook Messenger (Change page_id111009301424827 to your page_id).

add_action('wp_footer', 'add_facebook_messenger_script_footer');
function add_facebook_messenger_script_footer()
{
    ?>
    <!-- Messenger Chat Plugin Code -->
    <div id="fb-root"></div>
    <div id="fb-customer-chat" class="fb-customerchat"></div>
    <script>
        window.addEventListener('load', function () {
            var is_facebook_load = 0
            var chatbox = document.getElementById('fb-customer-chat');
            <!-- Thay page_id 111009301424827 thành page_id của bạn -->
            chatbox.setAttribute("page_id", "111009301424827");
            chatbox.setAttribute("attribution", "biz_inbox");

            window.addEventListener('scroll', function () {
                if (is_facebook_load == 0) {
                    is_facebook_load = 1;
                    window.fbAsyncInit = function () {
                        FB.init({
                            xfbml: true,
                            version: 'v15.0'
                        });
                    };
                    (function (d, s, id) {
                        var js, fjs = d.getElementsByTagName(s)[0];
                        if (d.getElementById(id)) return;
                        js = d.createElement(s);
                        js.id = id;
                        js.src = 'https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js';
                        fjs.parentNode.insertBefore(js, fjs);
                    }(document, 'script', 'facebook-jssdk'));
                }
            }, false);
        });
    </script>
    <?php
}

The above are ways to optimize Google speed, fix FB Like share page, comment, chat messenger to slow down the web when integrated into your website so as not to reduce page load performance as well as help you get the best score. Multi on speed test tools. In addition, if you also use Analytics or Google adsense , you can do the same.

– Advertising –

Share this Article
Facebook Twitter Pinterest LinkedIn Reddit Telegram
Leave a comment Leave a comment
Subscribe
Connect with
Login
Notify of
guest
Connect with
guest
0 Comments
Inline Feedbacks
View all comments
Previous Article WP Rocket Pro v3.15.3 Plugin - How to speed up WordPress Download WP Rocket Pro v3.15.3 to Speed Up WordPress
Next Article SmartMag v9.1.0 – Best magazine WordPress theme & news SmartMag v9.3.0 – Best Magazine WordPress Theme & News

You Might Also Like

Prevent Spam Register Plugin – Block WordPress Spam Accounts

How to Disable and Secure WP JSON API in WordPress

How to install Magento 2.4 on Ubuntu 22.04 with Composer

How to fix errors & change all WordPress links to a new domain

Newsprk v6.1.0 – WordPress theme Magazine and Blogs

Stay Connected

Facebook Like
Twitter Follow
Pinterest Pin
Telegram Follow

Popular Posts

Download Office 2024 Professional Plus Preview LTSC AIO Full Repack + Activate + Multilanguage
Download Office 2024 Professional Plus Preview LTSC AIO
December 9, 2023 2 Views
Download Adobe Photoshop 2024 v25.2.0.196 Repack (Full Activated)
Photoshop 2024 Repack v25.2.0.196 Full + AI / Neural Filters
December 9, 2023 442 Views
Download IDM FULL Crack v6.42.2 + Repack (Fix fake serial)
Download IDM FULL Crack v6.42.2 + Repack (Fix fake serial)
December 8, 2023 689 Views
Download WPBakery v7.2 Drag and Drop WordPress Page Builder Plugins
WPBakery v7.2 Drag and Drop WordPress Page Builder Plugins
December 4, 2023 27 Views
Download Plugin Product Video Gallery for Woocommerce v1.5.0
Plugin Product Video Gallery for Woocommerce v1.5.0
November 17, 2023 11 Views
Download Prevent Spam Register Plugin - Block WordPress Spam Accounts
Prevent Spam Register Plugin – Block WordPress Spam Accounts
November 17, 2023 17 Views
We provide tips and tricks on Internet technology, computers, servers as well as share experiences for developers and website designers.

DMCA.com Protection Status

Quick Link

  • Linux | Ubuntu
  • Windows & Software
  • Magento Developer
  • Wordpress Plugin
  • Wordpress Theme

General Policy

  • About US
  • Contact US
  • Disclaimer
  • Privacy Policy
  • Terms of Service

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

itsmeit.bizitsmeit.biz
Follow US
Copyright © 2023. All Rights Reserved.
  • WP Blog Theme
  • WP Fashion Theme
  • WooCommerce Theme
  • Wordpress Plugin
Welcome Back!

Sign in to your account

Continue with Google
Continue with TikTok
Continue with GitHub
Register Lost your password?