Search code examples
htmlimagegoogle-chromeprefetchprerender

How to prefetch and prerender an entire file of images


I have a bunch of images stored in XYZ.com/images/page1

The images are all pretty similar like image1.png, image2.png, etc. So the URL is XYZ.com/images/page1/image1.png

Is there a way to prefetch/prerender all images in the file for a page?


Solution

  • The following PHP file automatically shows all the images in your folder, and you don’t have to manually update anything, just upload to the folder.

    <?php
    $folder = 'images/page1/';
    $filetype = '*.*';
    $files = 
    
    glob($folder.$filetype);
    $count = count($files);
    echo '<table>';
    for ($i = 0; $i < $count; 
    
    $i++) {
    echo '<tr><td>';
    echo '<a name="'.$i.'" 
    
    href="#'.$i.'">
    <img src="'.$files[$i].'" 
    
    /></a>';
    echo
    substr($files[$i],strlen($folder), strpos($files[$i], '.')-strlen($folder));
    echo '</td></tr>';
    }
    echo '</table>';
    ?>