Lazy loading on instagram images to improve performance

lazy load can help a website that use this plugin (totally media center) to improve the general performance loading the images on-scroll only

  • Guest
  • Nov 16 2019
  • Shipped
  • Admin
    Helga R commented
    August 17, 2022 12:23

    Hello folks!

    Big news is coming — lazy load beta version for embedded widgets is here! 😍

    It doesn't work as a built-in option yet due to a couple of unresolved matters, but you can adjust your widget manually in order to make it work :)


    To turn it on, please add the “data-elfsight-app-lazy” attribute to a <div> element in your installation code.


    For example, here’s how the code looks like initially:

    <script src="https://apps.elfsight.com/p/platform.js" defer></script>
    
    <div class="elfsight-app-9d3beb9e-4c72-4bd1-8ed6-c192fc9e56c7"></div>


    And here’s how it should look like with the attribute added:

    <script src="https://apps.elfsight.com/p/platform.js" defer></script>
    
    <div class="elfsight-app-9d3beb9e-4c72-4bd1-8ed6-c192fc9e56c7" data-elfsight-app-lazy></div>


    Please keep in mind that it will work only for widgets which are not in the initial viewport (e.g. users have to scroll down at least for a little bit before they reach the widget).

    Please do let us know if it worked on your end 🙂


  • Chris Freer commented
    November 16, 2021 09:42

    Hi, being able to lazyload or reduce the image size would help alot with Google mobile page load times.


  • Admin
    Helga R commented
    June 30, 2021 14:11

    Dear folks,

    Thanks a lot for adding this idea and for your comments!

    We do understand how needed this option is for you and I'm truly sorry that we don't support it yet.

    We've tried to talk this option through, however, it did appear to be more complicated than we expected. To release the lazy load function, we'll have to implement a major update for the whole widget which is a very complex task.

    We're not going to give up on this idea of course, and we will definitely keep trying to find maybe other ways to make this option real. But unfortunately, we cannot promise that this will be done in near future.

    I'm so very sorry to bring such news, and I do believe we will be able to have this option released sooner.

    Thank you so much for your understanding! 🙏🏻

  • Jens Martsch commented
    June 30, 2021 09:58

    43 at the moment, and still "under consideration". It has been 1.5 years now, since this was posted.

  • Jens Martsch commented
    March 20, 2020 14:59

    Lazysizes with unveilhooks is a good option for this. However there should be a native solution.

    It can be done like this with plain JavaScript(ES6 format) and a little help of jQuery (you could also rewrite this without using jQuery):

    let instagramFeedScrollDistance;

    let instagramLoaded = false;

    function lazyLoadInstagramFeed() {

    let scrollDistance = $(window).scrollTop();

    let windowHeight = $(window).height();

    if ((scrollDistance >= (instagramFeedScrollDistance - windowHeight)) && !instagramLoaded) {

    let instagramScript = $.getScript('//apps.elfsight.com/p/platform.js');

    instagramLoaded = true;

    }

    }

    $(() => {

    const feed = $('.class-with-your-app-id');

    if (feed.length) {

    instagramFeedScrollDistance = feed.offset().top;

    instagramLoaded = false;

    $(window).on('scroll', lazyLoadInstagramFeed);

    lazyLoadInstagramFeed();

    }

    });

    A native approach with IntersectionObserver would be even better, but isn't suppported in IE.

  • Patrick commented
    March 02, 2020 22:38

    Hi guys,

    I managed to workaround this using the lazysizes JS library and their unveilhooks extension

    https://github.com/aFarkas/lazysizes

    https://github.com/aFarkas/lazysizes/blob/gh-pages/plugins/unveilhooks/ls.unveilhooks.js

    <div class="lazyload" data-script="link-to-elfsight-widget.js"></div>