Tuesday, January 08, 2013

Load LinkedIn API asynchronously


  1. Use the async version of the API
    http://platform.linkedin.com/in.js?async=true
  2. Load the library asynchronously
    <script type="text/javascript">
    (function()
    {
    var e = document.createElement('script');
    e.type = 'text/javascript';
    e.async = false;
    e.src = 'http://platform.linkedin.com/in.js?async=true';
    e.onload = function(){IN.init() };
    var s = document.getElementsByTagName('script')[0];
      s.parentNode.insertBefore(e, s);
    })();
    </script>
You may provide additional parameters like  "onLoad" -callback function & APIKey
in the call to IN.init({Param1:Value1, Param2:Value2})

2 comments:

Roshan Nanayakkara said...

(function()
{
var e = document.createElement('script');
e.type = 'text/javascript';
e.async = false;
e.src = 'http://platform.linkedin.com/in.js?async=true';
e.onload = function(){
IN.init({api_key: 'm1ayu5f49yhi', authorize: true});
UI_Anci.onLinkedInLoad();
};

var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(e, s);
})();


Thanks for your post, you are a life saver.
This will give the flexibility of loading the linkedin api on demand. rim

lezardo said...

I can't understand why you are setting e.async to false. For async loading it should have a true value right ?