Why does window.fbAsyncInit function come before that and not after?
You can write this code anywhere in you wish.
Won't the browser try to run it before it actually gets to the second part of the code where the SDK is actually loaded?
window.fbAsyncInit
is triggered after the SDK is loaded asynchronously, so it doesn't matter where you write this- before/after or anywhere.
Is it possible that all.js is loaded in the DOM only after FB.init() is called, thus generating an error?
What error? Btw, all.js cannot be loaded after FB.init. It's the reverse process- FB
can be initialized only after the SDK is loaded! Once the SDK is loaded it will automatically come inside- window.fbAsyncInit = function() {