-1

This question is similar to this one.

I'm generating images in a webpage with the following PHP in combination with lazyload.js. The purpose of this PHP is to automatically/dynamically load images from a given directory and to avoid direct hyperlinking. When I try to use various sitemap generators (both online and downloaded), they are only able to see the loader.gif and not seeing the real images being loaded. I know I can manually create an image sitemap .xml and upload to the Google Search Console, but I'd like to avoid that since I have tons of images, many of which will likely change periodically.

Is PHP like this uncrawlable? Is there another, more elegant solution for generating images dynamically like this, that will play nicely with crawlers? Thanks in advance.

<?php
            $dirname = "images/directoryname/";
            $images = scandir($dirname);
            $ignore = Array(".", "..");
            foreach($images as $curimg){
                if(!in_array($curimg, $ignore)) {
                    echo "<img class=\"img-responsive lazy\" src=\"images/loader.gif\" data-original='".$dirname.$curimg."' alt='Alt text goes here' /><br>";
                }
            }                 
            ?>
Community
  • 1
  • 1
  • sitemap generators are going to get all images from the source of your page, not parse the javascript like a browser to get a list of images that may be loaded. Google on the other hand usually can parse the javascript, but not sure myself if you would to get stuff like the images. You could just turn off the lazy loading for a few minutes while a site generator spiders your site or even disable it if you see googlebot. – Jonathan Kuhn Aug 20 '15 at 18:13
  • @JonathanKuhn that makes sense. So the issue is not PHP, it's javascript related? – chickenorbeef Aug 20 '15 at 18:30
  • yes. the site crawlers that generate your sitemaps will just pull the source of the page and look for all ` – Jonathan Kuhn Aug 20 '15 at 18:51
  • Thanks dude! @JonathanKuhn – chickenorbeef Aug 20 '15 at 21:23
  • If that answers your question I posted it as an answer. Feel free to accept so this can be closed. – Jonathan Kuhn Aug 20 '15 at 21:30

1 Answers1

0

sitemap generators are going to get all images from the source of your page, not parse the javascript like a browser to get a list of images that may be loaded. Google on the other hand usually can parse the javascript, but not sure myself if you would to get stuff like the images. You could just turn off the lazy loading for a few minutes while a site generator spiders your site or even disable it if you see googlebot.

the site crawlers that generate your sitemaps will just pull the source of the page and look for all <img tags and pull their src value. Not run the javascript to get everything that is lazy loaded via javascript.

Jonathan Kuhn
  • 15,279
  • 3
  • 32
  • 43