spicywebau / craft-embedded-assets

Manage YouTube videos, Instagram photos and more as first class assets in Craft CMS
MIT License
171 stars 35 forks source link

Option to add loading="lazy" to iframes #214

Closed stuible closed 2 years ago

stuible commented 2 years ago

Description

It would be great if we could opt for lazy loading iframe embeds which could improve website loading performance. Alternatively, it would be awesome if we could append custom attributes to the iframe element in twig.

Love the plugin so far!

ttempleton commented 2 years ago

Using Twig, this could be achieved with the attr filter:

{{ craft.embeddedAssets.get(element.embeddedAsset.one()).html|attr({ loading: 'lazy' }) }}

It makes sense for this to be an in-built option for the embedded asset getIframeCode() method, though, so will look at adding that soon.

ttempleton commented 2 years ago

Just released Embedded Assets 3.0.4 with a second parameter for getIframeCode() for adding attributes to iframes, in the format attribute or attribute=value (see the templating documentation for an example).