Facebook comments load very slowly

Facebook comment component loads the same JavaScripts multiple times and slows our page down from 1.2+ seconds, sometimes loads in 29 seconds

Please, help.

The script is at the bottom of the HTML source, we get it from the Facebook developer API

http://www.247polls.com/polls/should-marijuana-be-legalized/

enter image description here

+3


source to share


2 answers


FB.XFBML.parse();

      

Your comments will be loaded even if the page has not finished loading:

<script>
    window.fbAsyncInit = function () {
        FB.init({appId: 'YOUR-APP-ID', version: 2.4, xfbml: true});

        if (typeof facebookInit == 'function') {
            facebookInit();
        }
    };

    (function () {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
    }());


    function facebookInit() {
        console.log('Loading comments...');
        FB.XFBML.parse();
    }
</script>

      



Another thing to improve speed is limiting the number of comments displayed from num_posts

to 5.

Keep swinging!

+1


source


add js.async=true;

and make sure you follow this doc:

https://developers.facebook.com/docs/plugins/comments/



ref: https://geekflare.com/load-facebook-like-and-share-button-faster/

0


source







All Articles