starfishmod / jquery-oembed-all

A fork with improvements of the jquery-oembed project
http://starfishmod.github.com/jquery-oembed-all
386 stars 160 forks source link

Delay multiple oembed calls #77

Open 0x0ece opened 11 years ago

0x0ece commented 11 years ago

I have a page with many (say 20) youtube videos to oembed. Calling oembed on all them simultaneously slows down a lot the browser. I've tried substituting the call:

$("a.embed").oembed(...);

with:

setInterval(function(){ $("a.embed:first").oembed(...); }, 2000);

Note that I'm using 'replace' within the options, so once a link is embedded, the original link is no longer available in the dom. That's why :first actually works (i.e. printing the urls, I can verify that the loop is correct).

Unfortunately the library seems not to work properly. The result is that:

The same behaviour can be seen using jquery queues, for instance:

$('a.embed').each(function() {
    var a = $(this);
    body.queue('oembedQueue', function(next) {
        a.oembed(...);
        next();
    }).delay(2000, 'oembedQueue');
});
body.dequeue('oembedQueue');

In this second example, removing the delay() causes the embed to be almost simultaneous (like the $("a.embed").oembed(...); call) and properly works. It seems to me that there is some strange internal behaviour that works badly with concurrency...

MattOpen commented 10 years ago

maybe there is another prob. For each e.g. youtube player, lots of files were loaded. lets say we load 10 video. The result is 10 times load https://s.ytimg.com/yts/swfbin/player-vflLstCoX/watch_as3.swf with 291.5 kb https://s.ytimg.com/yts/cssbin/www-embed-player-vflvSgpSH.css with 23.4 kb https://s.ytimg.com/yts/jsbin/www-embed-player-vfldFMlKN/www-embed-player.js with 64.8 kb

sum load over 3000 kb