I’m trying to use the Youtube Iframe API inside a module definded with Require JS. As this API is loaded async and calls a function once is loaded, I used a requireJS plugin called “async”, that worked before with google maps api.
However, this time something isn’t working. My module starts this way:
define(['text!fmwk/widgets/video/video.html','fmwk/utils/browser','async!http://www.youtube.com/iframe_api'], function (videoTpl,root) { ... });
and chrome console fires this error:
Uncaught Error: Load timeout for modules: async!http://www.youtube.com/iframe_api_unnormalized3,async!http://www.youtube.com/iframe_api
http://requirejs.org/docs/errors.html#timeout
If I don’t use async plugin the object YT or its functions are undefinded, and the same happens if I download the API code. The API is loaded sometimes if I put an script tag in the head tag of the html file. All this is expected, but I don’t understand because async plugin fails.
Thank you for your attention and help 🙂
I’m not familiar with the
asyncrequireJS plugin, but here’s some sample code (taken from YouTube Direct Lite) that loads the iframe API asynchronously from within a requireJS module namedplayer. It’s using jQuery to do the actual library loading, though.