Want more features on Pastebin? Sign Up, it's FREE!
Guest

Defer javascript and asynchronous loading of social plugin

By: a guest on Jun 28th, 2012  |  syntax: JavaScript  |  size: 1.33 KB  |  views: 683  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <!-- FB code for asynchronous loading -->
  2. <script type="text/javascript">
  3.     // prevent jQuery from appending cache busting string to the end of the FeatureLoader URL
  4.     var cache = jQuery.ajaxSettings.cache;
  5.     jQuery.ajaxSettings.cache = true;
  6.     // Load FeatureLoader asynchronously. Once loaded, we execute Facebook init
  7.     jQuery.getScript('http://connect.facebook.net/en_US/all.js', function() {
  8.     FB.init({appId: 'your-app-id', status: true, cookie: true, xfbml: true});
  9.     });
  10.     // just Restore jQuery caching setting
  11.     jQuery.ajaxSettings.cache = cache;
  12.     </script>
  13.  
  14.  
  15. <!-- Gplus button asynchronous loading -->
  16. <script type="text/javascript">
  17.   (function() {
  18.     var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
  19.     po.src = 'https://apis.google.com/js/plusone.js';
  20.     var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  21.   })();
  22. </script>
  23.  
  24.  
  25. <!-- Gplus button defer script -->
  26. <script defer="defer" type="text/javascript">
  27.     window.onload=function(){
  28.         var mycode;
  29.         mycode=document.createElement("script");
  30.         mycode.type="text/javascript";
  31.         mycode.src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js";
  32.         document.getElementsByTagName("head")[0].appendChild(mycode);
  33.     }
  34. </script>
clone this paste RAW Paste Data