An option to specify lazy image loading would be great.
Something like this:
And the output would be: <img src="..." loading="lazy">
(See "loading" <img>: The Image Embed element - HTML: HyperText Markup Language | MDN)
An option to specify lazy image loading would be great.
Something like this:
And the output would be: <img src="..." loading="lazy">
(See "loading" <img>: The Image Embed element - HTML: HyperText Markup Language | MDN)
@marcellothearcane, not sure I can make that happen with an image inserted in Rich Text.
You’re right. That wouldn’t be possible - what you could do instead is have a ‘lazily load images’ boolean just below your rich text. I presume you would want to lazy load all the images if at all.
Is there an example somewhere? I’m using prismic-reactjs
RichText.render()
to render the images from a rich text field.
Hi Jerry,
I’ll be happy to help.
You can do lazyloading with our Imgix integration and the lazysizes plugin.
This article explains how to do so.
But essentially to set this up you just need to
There’s also the react-imgix plugin.
Let me know if this helps.
Thanks.
I think part of the puzzle is not having control over what prismic-dom produces from a richtext field.
You can always use an HTML Serializer to control the output from a Rich Text field:
https://prismic.io/docs/javascript/beyond-the-api/html-serializer
Thanks for pointing me in the right direction. I’m using Next.js so my serializer needs to return React elements, correct? Is there an example somewhere?
Yeah, here is an example HTML Serializer for the prismic-reactjs
library:
https://prismic.io/docs/reactjs/beyond-the-api/html-serializer