7

I wish to load the Vimeo player API asynchronously, using something like:

var tag = document.createElement('script')
tag.src = 'https://player.vimeo.com/api/player.js'
var firstScriptTag = document.getElementsByTagName('script')[0]
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag)

This works fine, though the side effect is that I now need a mechanism to determine when the API has loaded, to initialize a player accordingly. I could use a setInterval() to poll and detect when the Vimeo variable is available I guess, though I was hoping for a more elegant, events based approach, something like:

Vimeo.on('loaded', function(){
    new Vimeo.Player('myplayer')
})

Any ideas?

coco puffs
  • 1,040
  • 12
  • 8

0 Answers0