Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save johnbacon/4430125 to your computer and use it in GitHub Desktop.

Select an option

Save johnbacon/4430125 to your computer and use it in GitHub Desktop.

Revisions

  1. johnbacon revised this gist Jan 1, 2013. 1 changed file with 18 additions and 18 deletions.
    36 changes: 18 additions & 18 deletions Facebook - Non-Blocking Script Loader Pattern
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,19 @@
    (function() {
    var url = '//connect.facebook.net/en_US/all.js';
    var iframe = document.createElement('iframe');
    (iframe.frameElement || iframe).style.cssText = "width: 0; height: 0; border: 0";
    iframe.src = "javascript:false";
    document.getElementById('fb-root').appendChild(iframe);
    var doc = iframe.contentWindow.document;
    doc.open().write('<body onload="'+
    'window.inDapIF = true;' +
    'var js = document.createElement(\'script\');'+
    'js.src = \''+ url +'\';'+
    'document.body.appendChild(js);">');
    doc.close();
    }());
    (function() {
    var url = '//connect.facebook.net/en_US/all.js';
    var iframe = document.createElement('iframe');
    (iframe.frameElement || iframe).style.cssText = "width: 0; height: 0; border: 0";
    iframe.src = "javascript:false";
    document.getElementById('fb-root').appendChild(iframe);
    var doc = iframe.contentWindow.document;
    doc.open().write('<body onload="'+
    'window.inDapIF = true;' +
    'var js = document.createElement(\'script\');'+
    'js.src = \''+ url +'\';'+
    'document.body.appendChild(js);">');
    doc.close();
    }());

    // async init once loading is done
    window.fbAsyncInit = function() {
    FB.init({xfbml: true});
    };
    // async init once loading is done
    window.fbAsyncInit = function() {
    FB.init({xfbml: true});
    };
  2. johnbacon created this gist Jan 1, 2013.
    19 changes: 19 additions & 0 deletions Facebook - Non-Blocking Script Loader Pattern
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    (function() {
    var url = '//connect.facebook.net/en_US/all.js';
    var iframe = document.createElement('iframe');
    (iframe.frameElement || iframe).style.cssText = "width: 0; height: 0; border: 0";
    iframe.src = "javascript:false";
    document.getElementById('fb-root').appendChild(iframe);
    var doc = iframe.contentWindow.document;
    doc.open().write('<body onload="'+
    'window.inDapIF = true;' +
    'var js = document.createElement(\'script\');'+
    'js.src = \''+ url +'\';'+
    'document.body.appendChild(js);">');
    doc.close();
    }());

    // async init once loading is done
    window.fbAsyncInit = function() {
    FB.init({xfbml: true});
    };
    18 changes: 18 additions & 0 deletions General - Non-Blocking Script Loader Pattern
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    (function(url){
    // Section 1
    var iframe = document.createElement('iframe');
    iframe.src = "javascript:false";
    (iframe.frameElement || iframe).style.cssText = "width: 0; height: 0; border: 0";
    var where = document.getElementsByTagName('script');
    where = where[where.length - 1];
    where.parentNode.insertBefore(iframe, where);

    // Section 2
    var doc = iframe.contentWindow.document;
    doc.open().write('<body onload="'+
    'var js = document.createElement(\'script\');'+
    'js.id = \'js-iframe-async\';'+
    'js.src = \''+ url +'\';'+
    'document.body.appendChild(js);">');
    doc.close();
    })('http://some.site.com/script.js');