Chapter 4. The Art and Craft of the Async Snippet
JavaScript downloads block the loading of other page components. That’s why it’s important (make that critical) to load script files in a nonblocking asynchronous fashion. If this is new to you, you can start with this post on the Yahoo User Interface (YUI) library blog (http://www.yuiblog.com/blog/2008/07/22/non-blocking-scripts/) or the Performance Calendar article (http://calendar.perfplanet.com/2010/the-truth-about-non-blocking-javascript/).
In this post, I’ll examine the topic from the perspective of a third party—when you’re the third party, providing a snippet for other developers to include on their pages. Be it an ad, a plug-in, widget, visits counter, analytics, or anything else.
Let’s see in much detail how this issue is addressed in Facebook’s JavaScript SDK.
The Facebook Plug-ins JS SDK
The Facebook JavaScript SDK is a multipurpose piece of code that lets you integrate Facebook services, make API calls, and load social plug-ins such as the Like button (https://developers.facebook.com/docs/reference/plugins/like/).
The task of the SDK when it comes to Like button and other social
plug-ins is to parse the page’s HTML code looking for elements (such as
<fb:like> or <div class="fb-like">) to replace with a
plug-in. The plug-in itself is an iframe that points to something like
facebook.com/plugins/like.php with the
appropriate URL parameters and appropriately sized.
This is an example of one such plug-in URL:
https://www.facebook.com/plugins/like.php?href=bookofspeed.com&layout=box_count ...