• Resolved jordanwebdev

    (@jordanwebdev)


    Whenever I use AJAX to load content from another page of my site, only the 1×1 placeholder comes in. How do I reinitialize JetPack’s lazy images to pop the proper image back in after Ajax? Is there a reinitialize function I can use in JavaScript?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    Thanks for the report. That’s something we should be able to fix in Jetpack directly.

    Do you use a specific plugin to bring in content via AJAX like this, so we can run some more tests?

    Thread Starter jordanwebdev

    (@jordanwebdev)

    No, I created the AJAX call myself. Just a basic jQuery load, loading HTML from one page into the current one.

    Is there anything I can do now? We’re launching the site soon so I can’t wait for the update.

    Thread Starter jordanwebdev

    (@jordanwebdev)

    For everyone with this same problem, I came up with this solution. It checks if the 1×1 exists first, so in theory when JetPack updates their plugin, this code won’t even run.

    function update_thumbs() {
        $('YOUR IMAGE SELECTOR').each(function() {
          var src = $(this).prop('src');
          if (src.indexOf('1x1.trans.gif') !== -1) {
            $(this).prop('src', $(this).data('orig-file'));
          }
        });
      }
    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    Thanks for the extra details. That is not something we support just yet, but I took note of it here:
    https://github.com/Automattic/jetpack/issues/9043

    Until then, your workaround should indeed work just fine!

    Thread Starter jordanwebdev

    (@jordanwebdev)

    It worked on one site, but I tried it on another site, and the thumbs don’t appear to have the “orig-file” data attribute, so I’m trying to figure out a new solution…

    I think this one works as an alternative:

    $(this).prop('src', $(this).data('lazy-src'));

    • This reply was modified 6 years, 12 months ago by jordanwebdev.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Using AJAX only loads 1×1 lazy placeholder’ is closed to new replies.