Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Chris Van Oort 110 posts 371 karma points
    Aug 14, 2023 @ 14:24
    Chris Van Oort
    0

    Automatically insert loading="lazy", height, and width attributes on grid images?

    Google pagespeed is dinging us for not having height and width attributes on all of our images, but one of the other things we discovered is that there is a browser supported function for lazy loading images. ( https://caniuse.com/loading-lazy-attr ) Browsers that don't support the attribute don't process anything so the images load the same -- pretty nice for backwards compatiblity.

    More Info: https://web.dev/browser-level-image-lazy-loading/

    Are there any strategies to automatically insert loading="lazy", height, and width attributes on grid images?

    Thank you!

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Aug 14, 2023 @ 15:14
    Marc Goodson
    0

    Hi Chris

    With the old grid, you can update the rendering of images in the partial view:

    /Views/Partials/grid/editors/media.cshtml

    to update the img tag.

    I'm not sure you've seen the plugin called 'Slimsy':

    https://github.com/Jeavon/Slimsy

    It does a lot of the hard work for generating responsive and lazy images...

    but also on the Slimsy demo site, they have an example of how they have updated the above partial view to customise the img tag:

    https://github.com/Jeavon/Slimsy/blob/dev-v4/src/Slimsy.TestSite/Views/Partials/grid/editors/media.cshtml

    but all you might need to do is add the new attribute in the img tag!

    Slimsy might get you a better page score though!

    regards

    marc

  • Chris Van Oort 110 posts 371 karma points
    Aug 14, 2023 @ 15:29
    Chris Van Oort
    0

    Slimsy looks interesting, but I think we're looking for options like the /Views/Partials/grid/editors/media.cshtml

    Do you know how the RTE media picker applies attributes / where that is done? (it would be nice to modify that for future media picker embeds in RTE. I can modify the existing ones via uSync + reimport)

  • Chris Van Oort 110 posts 371 karma points
    Aug 14, 2023 @ 16:57
    Chris Van Oort
    0

    It also appears that when I edit and hit save on the RTE, it is scrubbing/removing the loading="lazy" attribute. Thus, even manually editing doesn't stick.

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Aug 15, 2023 @ 07:39
    Huw Reddick
    0

    you need to add loading to the allowed attributes for img in the ValidElements for the RTE

Please Sign in or register to post replies

Write your reply to:

Draft