#88442Allow iframe / video (youtube) javascript loading with "defer"
Description
Allow loading a video through a kind of “defer” loading.
For example, the f:media viewhelper with an additional attribute defer = “true”.
This makes it necessary to include additional JavaScript, as described here:
https://varvy.com/pagespeed/defer-videos.html
This could potentially improve the load time of the website.
Reviews 1
History 12
-
Christian Hackl changed subject
Allow Iframe / Video javascript loading with "defer"Allow iframe / video (youtube) javascript loading with "defer" <span data-processor="relativetime" data-value="2019-05-26T22:02:55+00:00" > 05/26/19, 22:02 </span> -
Christian Hackl commented <span data-processor="relativetime" data-value="2019-09-26T15:06:34+00:00" > 09/26/19, 15:06 </span>
my current solution is: https://extensions.typo3.org/extension/hh_video_extender/
currently not the best code, but it does what it should
-
Georg Ringer commented and changed status
NewNeeds Feedback <span data-processor="relativetime" data-value="2020-03-28T21:47:44+00:00" > 03/28/20, 21:47 </span>this is already possible by default using
<f:media class="video-embed-item" file="{file}" width="{dimensions.width}" height="{dimensions.height}" alt="{file.alternative}" title="{file.title}" additionalConfig="{additionalAttributes:{defer:'defer'}}" />is that solution ok for you?
-
Christian Eßl commented <span data-processor="relativetime" data-value="2020-03-28T22:06:52+00:00" > 03/28/20, 22:06 </span>
No, there is no native “defer” attribute for html videos, so the browser wouldn’t know from that information alone, that the video needs to be “lazyloaded”.
For doing so, you would also need to override the “src” attribute to something like “data-src” and handle the lazyloading logic, that replaces “data-src” with “src” in some custom javascript. Otherwise the src would always be fetchedQuestion is: Should the core viewhelper support that (to override the attribute name for “src”) or should this not be done in the core and better be done by third-party extension code, that implement their own video viewhelper solutions?
https://developers.google.com/web/fundamentals/performance/lazy-loading-guidance/images-and-video#for_video_acting_as_an_animated_gif_replacement
Lazy loading videos is still a bit “tricky” to support all browsers and scenarios well enough. -
Christian Hackl commented <span data-processor="relativetime" data-value="2020-03-29T18:44:19+00:00" > 03/29/20, 18:44 </span>
Yes, unfortunately you’re right, especially now with all the privacy data stuff and the needed javascript.
Maybe it’s not wise to put something like that into the core – it could be a bit tricky with the CookieConsent plugins, at least for users in the EU.
Hmm stupid… or?! -
Stephan Bauer commented <span data-processor="relativetime" data-value="2022-01-06T23:22:22+00:00" > 01/06/22, 23:22 </span>
Chrome supports lazy loading for iframes https://caniuse.com/?search=loading
I made a patch witch includes that:
https://forge.typo3.org/issues/96477 -
Benni Mack commented <span data-processor="relativetime" data-value="2024-06-17T19:54:00+00:00" > 06/17/24, 19:54 </span>
We integrated “loading=lazy” for images, we could add this for videos via iframe now as well, as <f:media> VH can deal with this already.</f:media>
-
Christoph Schwob commented <span data-processor="relativetime" data-value="2026-03-17T18:46:16+00:00" > 03/17/26, 18:46 </span>
Benni Mack wrote in #note-8:
> We integrated “loading=lazy” for images, we could add this for videos via iframe now as well, as <f:media> VH can deal with this already.</f:media>The `loading=lazy` parameter is also ignored by the YouTubeRenderer if it’s set as a parameter in `f:media`. It must be added separately as `additionalAttributes`. (Tested in 12.4.42)
-
Garvin Hicking commented <span data-processor="relativetime" data-value="2026-03-17T18:51:36+00:00" > 03/17/26, 18:51 </span>
(12.4 is too old for this; fluid supports it in v13&v14) to habe arbitrary attributes.
-
Riccardo De Contardi commented <span data-processor="relativetime" data-value="2026-07-01T13:41:01+00:00" > 07/01/26, 13:41 </span>
I think this is already solved with https://review.typo3.org/c/Packages/TYPO3.CMS/+/92345 that should allow you to write something like:
<f:media file="{youtubeVideo}" additionalConfig="{srcAttribute: 'data-src'}" /> -
Georg Ringer commented and changed status
Needs FeedbackClosed <span data-processor="relativetime" data-value="2026-10-16T15:00:20+00:00" > 10/16/26, 15:00 </span>Thanks for the request. The use case is covered in current versions, so I’m closing this issue.
- Delaying the load of the embed (the actual “defer” idea): since v14.2 (#108648) the
YouTubeRendererandVimeoRendereraccept the optionsrcAttribute, which renames the hard-codedsrcattribute of the iframe. Combined with a small piece of JavaScript (or a consent tool) that movesdata-srctosrc, nothing is fetched up front:
<f:media file="{youtubeVideo}" additionalConfig="{srcAttribute: 'data-src'}" />- Native lazy loading of the iframe can be set with arbitrary attributes, as Georg pointed out in the comments:
<f:media file="{youtubeVideo}" additionalConfig="{additionalAttributes: {loading: 'lazy'}}" />The
loadingargument off:mediais documented for image files only and is not forwarded to the online media renderers. The related request for the privacy case (#96477) is already closed.If this is still valid for you in v14, please open a new issue and provide information how to reproduce it. Thanks!
- Delaying the load of the embed (the actual “defer” idea): since v14.2 (#108648) the
This would be a very helpful addition.
Just recently I created a very similar solution by overriding the YouTubeRenderer, but other video media types would also benefit from this feature. I will try to create a patch later.