kevinweber / lazy-load-for-videos

Speed up your site by replacing embedded Youtube and Vimeo videos with a clickable preview image. Free WordPress plugin.
http://wordpress.org/plugins/lazy-load-for-videos/
GNU General Public License v3.0
41 stars 23 forks source link

Wrong embed code cached when Feed/AMP is loaded first #62

Open mjaschen opened 3 years ago

mjaschen commented 3 years ago

WordPress uses a cache for storing the embed markup after first retrieving it via oEmbed and transforming it to the lazy-load version afterwards. When Lazy Load for Videos is active, the transformed markup is stored in the cache instead of the original iframe.

However, the original oEmbed markup (iframe) is cached instead of the lazy-load version when the following conditions are met:

  1. the oEmbed cache for a post is empty or expired and
  2. the AMP or feed view of that post is requested first (before a regular post view).

If that happens, all Youtube/Vimeo videos aren't embedded with the lazy load markup but with the original oEmbed markup – at least until the oEmbed cache expires.

KW_LLV_Admin::lazyload_replace_video() checks for AMP/feed view and returns the oEmbed code markup unchanged. source. WordPress uses the result of that method as embed markup and caches it in the postmeta table.

My first idea was to use separate oEmbed cache entries (one for default view, one for feed view, one for AMP) but it seems that that isn't possible with the WordPress oEmbed logic.

This issue is partly related to #54.