Async widgets.js loader is not compatible with oct.js (initialize different twttr object -- missing "ready")


#1

in async loader we have:

return window.twttr || (t = {_e: [], ready: function(f) {
              t._e.push(f)
            }});

which prepares the convenient ‘ready’ function.

use this with oct.js, you will lost ‘ready’ function. because there’s no such ‘_e’ and ‘ready’ initialized for oct.js’s twttr object (unless you can make sure async code finishes first before oct.js).

This is my current solution now:

window.twttr = (function(d, s, id) {
          var t, js, fjs = d.getElementsByTagName(s)[0];
          if (d.getElementById(id))
            return;
          js = d.createElement(s);
          js.id = id;
          js.src = "https://platform.twitter.com/widgets.js";
          fjs.parentNode.insertBefore(js, fjs);
        
          // make async loader compatible with oct.js
          var _twttr = window.twttr || (t = {_e: [], ready: function(f) {
              t._e.push(f)
            }});
          
          if (! ('_e' in _twttr)) {
            _twttr._e = []
          }
          
          if (! ('ready' in _twttr)) {
            _twttr.ready = function(f) {
              _twttr._e.push(f)
            }
          }
          
          return _twttr
        }(document, "script", "twitter-wjs"));

Async widgets.js loader is not compatible with oct.js
#2

Hi Akhmad, thanks for letting us know about this. We’ll post a revised version of the async loader code soon. In the mean time, I’m glad you were able to get it working.

Ben


#3

Thanks for posting the workaround, Akhmad. Just run into this myself!


#4

Any official update on this one? It still seems broken.


#5

Is there any update to this issue ?
Following twitter official guides on both widget.js and oct.js and placing them both at the same page I will end up with twttr.ready() bombing out due to undefined as described by neofreko. The work around works fine, but I think you twitter guys should address this issue or at least warn about it in your guides ! This issue just caused us broken page in production - no ideal !


#6

Hi everyone. Sorry this took so long to get proper attention. We’ve updated our docs with a version of the async code node which fixes the assignment of ready() for coexistence with oct.js. Thanks to everyone who contributed workarounds in the interim.

Ben


#7