How can I load the PubNub JavaScript library asynchronously?

Options for asynchronous loading of the JavaScript SDK (in lieu of standard HTML inclusion via  <div> tag) include:

  1. Use the Lazy Loading Async method
  2. Facebook Style
  • Modify the PubNub JavaScript SDK to execute a global function
  • Define that function prior to async-loading the PubNub JS SDK
  • Using Require.JS
  • Using Head.JS
    • Call the head.js() function as you normally would, including the PubNub JavaScript SDK
    • Call the PUBNUB.init function inside the head.js callback:
head.js("/jquery.js", "http://cdn.pubnub.com/pubnub.js", 
    function() {
        var pubnub = PUBNUB.init({
            'publish_key' : 'pub-key', 
            'subscribe_key' : 'sub-key', 
            'ssl' : false });

        pubnub.ready();

        pubnub.subscribe({
            channel : 'abc', 
            callback : function(m) {alert(JSON.stringify(m))}});
    }
);