mpratt / Embera

A Oembed consumer library, that gives you information about urls. It helps you replace urls to youtube or vimeo for example, with their html embed code. It has advanced features like offline support, responsive embeds and caching support.
MIT License
335 stars 59 forks source link

Add an option for iframe lazyloading #102

Open jimblue opened 9 months ago

jimblue commented 9 months ago

Support for native iframe lazy loading is now pretty good : https://caniuse.com/loading-lazy-attr

This can be handled with a filter:

$embera->addFilter(static function ($response) use ($loading) {
            if (!empty($response['html'])) {
                $response['html'] = str_replace('<iframe', "<iframe loading=\"{$loading}\"", $response['html']);
            }

            return $response;
});

But IMO, it would be nicer to add a loading option to set this attribute when using autoEmbed(). Everyone should enjoy the joy of iframe lazyloading 😸

mpratt commented 5 months ago

Hi @jimblue Thanks for the suggestion. I'll be adding this as a config option on the next major release of this library.