Facebook sdk loaded asynchronously but PageSpeed says it was loaded synchronously

1,550 views
Skip to first unread message

Borja Martín

unread,
Jul 12, 2013, 6:50:02 AM7/12/13
to page-spee...@googlegroups.com
Hi,
I was testing one of our sites with the PageSpeed Insights web service and we got this warning:

The following resources are loaded synchronously. Load them asynchronously to reduce blocking of page rendering.

The point is that that's not true as we are using the snippet provided by Facebook to load the library asynchronously as it can be seen at the tested url:

(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

Is this a PageSpeed bug or is there something that is causing the Facebook library to be loaded synchronously?
Thank you
Regards

João Paulo Marinho Dantas

unread,
Oct 3, 2013, 9:44:21 PM10/3/13
to page-spee...@googlegroups.com
Hi, Borja, 

one of my clients ask me to check the same thing. 
Believe me, it's easier than you think. 
Try to change your code to this:

(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.async=true; //here's the magic
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

Let me know if this works for you.

Regards,
João Paulo Marinho

Libo Song

unread,
Oct 4, 2013, 8:15:53 AM10/4/13
to page-spee...@googlegroups.com
Thanks João for the suggestion.

PageSpeed Insights has fixed this problem recently. Any script that is added via a DOM element from JS is async by default. Therefore, we have fixed the detection about the facebook library.

Best,


--
You received this message because you are subscribed to the Google Groups "page-speed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to page-speed-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/page-speed-discuss/8195ba7e-1ffb-4988-8222-9f83441055d3%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Message has been deleted

Michael Pagenkopf

unread,
Jun 25, 2016, 5:11:33 PM6/25/16
to pagespeed-insights-discuss, page-spee...@googlegroups.com, bor...@dagi3d.net
A couple days later ....

Works perfect. Thanks!

Reply all
Reply to author
Forward
0 new messages