craft-videoembedder icon indicating copy to clipboard operation
craft-videoembedder copied to clipboard

Super slow when using 5 embeds

Open kevinmu17 opened this issue 5 years ago • 6 comments

Hi there,

First of all: Awesome plugin!

I'm running against a little(big) problem, when using 6 embeds at once, it becomes very very slow in loading the webpage. Even when i'm trying to only show the youtube Thumbnails.

I can't lay my finger on the way this plugin gets the Thumbnail URL.

kevinmu17 avatar Jun 26 '19 14:06 kevinmu17

Try caching your results? The plugin uses another PHP library to return everything. Essentially the plugin is just a wrapper for that library. Here is the function called for getting the thumbnail: https://github.com/oscarotero/Embed/blob/c8e1514861e7880f31e84b2c883bf31cff3e182a/src/Adapters/Adapter.php#L468

mikestecker avatar Oct 23 '19 22:10 mikestecker

Caching is not really a solution. The underlying problem is that when VideoEmbedderService->getInfo is called new Embed::create is called and that causes a new HTTP request.

A single youtube embed (with poster image) causes 10 (!) HTTP requests to the youtube domain. Simple per request caching brings this back to only 2 (with something like $this->infoCache[$url]).

I will probably drop a pull request later.

ghost avatar Nov 01 '19 13:11 ghost

I tried @renzo-s code in the linked file but it doesn't seem to load the videos.

adrianjean avatar Nov 26 '19 16:11 adrianjean

Try caching your results? The plugin uses another PHP library to return everything. Essentially the plugin is just a wrapper for that library. Here is the function called for getting the thumbnail: https://github.com/oscarotero/Embed/blob/c8e1514861e7880f31e84b2c883bf31cff3e182a/src/Adapters/Adapter.php#L468

Thanks, this is speeding up things again!

@renzo-s I'm calling the getVideoThumbnail function, the cache tag around this is a major improvement, it just returns a URL, can't seem to track down the 2 requests you mentioning.

kevinmu17 avatar Feb 13 '20 13:02 kevinmu17

Was there an end-solution for this? Assume if we use the @renzo-s solution, we'd need to change the core files?

terryupton avatar Oct 19 '20 13:10 terryupton

We have this fix in production for over a year without problems. If this is an issue for you @terryupton, and this repo seems dead, you can always install my fork, but I'm not actively developing that one either.

ghost avatar Oct 19 '20 15:10 ghost