lazy loading of H5P content

Created on 9 July 2024, 9 months ago

Problem/Motivation

In our project we have several pages that include multiple H5P objects and it makes sense to be able to lazy load them as the user scrolls down the page and brings them into view.

We do this routinely for images using the the lazy module and we extend the extend the functionality to the iframe module by overriding the iframe.html.twig Twig template to add in the required classes etc.

We do this with the following Twig (HTML) code in the template...

  <iframe class="lazyload"{{ attributes|without('class','src') }} loading="lazy" data-src="{{ src }}">
    {{ 'Your browser does not support iframes, but you can visit <a href=":url">@text</a>'|t({ ':url': src, '@text': text }) }}
  </iframe>

With H5P we cannot do that because it does not use any templates to wrap up the renderable content so we cannot target the <iframe> elements that way.

Is there a way we can achieve the same effect with H5P?

Thanks all

💬 Support request
Status

Active

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom SirClickALot Somerset

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024