Lazy Loading WYSIWYG Images

3 posts by 3 authors in: Forums > CMS Builder
Last Post: February 23, 2022   (RSS)

By KennyH - January 27, 2022

I am wanting to get loading="lazy" automatically added to images placed in the WYSIWYG content. I know how to have classes added to images automatically, but this one is giving me problems.

Any suggestions?

// configure image plugin
    toolbar: "image",
    image_caption: true,
    image_class_list: [
      {title: 'None', value: 'img-fluid m-1'},
      {title: 'Circle', value: 'rounded-circle img-fluid m-1'},
      {title: 'Rounded', value: 'rounded img-fluid m-1'},
      {title: 'Thumbnail', value: 'img-thumbnail img-fluid m-1'},
    ],
    visualblocks_default_state: false,
    end_container_on_empty_block: true,

By kitsguru - February 23, 2022 - edited: February 23, 2022

I use the javascript from github.com/aFarkas/lazysizes

Then all you need to do is add the class 'lazyload' to your class list.

    image_class_list: [
      {title: 'None', value: 'img-fluid m-1 lazyload'},
      {title: 'Circle', value: 'rounded-circle img-fluid m-1 lazyload'},
      {title: 'Rounded', value: 'rounded img-fluid m-1 lazyload'},
      {title: 'Thumbnail', value: 'img-thumbnail img-fluid m-1 lazyload'},
    ],

You couldĀ  then modify the img tag to use data-src instead of src by redifining the image button @see: https://stackoverflow.com/questions/45728568/how-to-change-default-html-for-adding-image-in-tinymce

Jeff Shields