Ashkan Mobayen Khiabani Ashkan Mobayen Khiabani - 25 days ago 8
HTML Question

Loading Images on demand without altering the src attribute

I have a website that 40 babynames are shown in each page, each name have some photos that are uploaded by users. I use iframes to show the images of each name when the user clicks on "show photos button" (iframe is created dynamically after click). Well in this case images are never indexed with search engines.

If I load them right after each name (and not in a iframe) then the page size will be very large and will load very slow.

I'm looking for a way that load images on demand (just as it is now) without using iframes. setting the src on demand will be in-vane as search engines won't have access to them and setting them will make page very heavy as I said before.

Any suggestions on how to do this?

Answer

You could use a php script that displays one singe thumbnail (1x1 pixels) when the query string ends on "small"; with ajax you can now access every single image and remove the ending "small" so that the php script uses the original file. http://php.net/manual/en/function.imagejpeg.php might help ^^

So you access "image.php?myimage.jpg-small" and the script loads the fixed thumbnail that will get cached after the first load. Then, you change the img src property using ajax to "image.php?myimage.jpg" and we're done...

You could use a .htaccess - rewrite for better look of the image source...

Comments