I would very much like the browser to prefetch or preload the next image in the particular album to optimize browsing performance. I realize that Test-JS has a JavaScript function for that purpose, but that theme is for testing purposes only at the moment. Would the `` tag be a simple way of making Mozilla-based browsers prefetch the next image?
Read about link prefetching here.
I inserted this code in the header section of image.php:
`<?php if (hasNextImage()) { ?>
" />
<?php } ?>`
However, since getNextImageURL() returns the URL to the
webpage containing the next image, not the URL to the image itself, I think the browser is just caching the next HTML content of the next page, but not the image.
How do I get the URL to the next image itself? That is, the URL in the `
` tag. I looked through the
Template Functions Guide but couldn't find any function that does that.
Maybe a function like `printNextDefaultSizedImage()` or `printNextCustomSizedImage()`?
Thanks in advance.
Comments
`if (hasNextImage()) {
next_image();
echo '';
}`
However, how do I return the context to the image I was on before I moved forward with `next_image()`?
I tried `set_context(ZP_IMAGE);` but that sends me to the first image in the album even if I wasn't viewing that image.
However, the approach you are taking will have problems with image pagination. I think a better approach is to use something like:
`$imagarray = $_zp_current_album->getImages(0);
$nextimage = $imagearray[imageNumber()+1];`
You do, of course, need to be sure there is a next image.
` $imagearray = $_zp_current_album->getImages(0);
$nextimage = $imagearray[imageNumber()];`
$nextimage is now a text string, the file name of the next image. But how do I get the URL to the default sized image of that name? getDefaultSizedImage() doesn't take parameters and only returns the default sized image URL of $_zp_current_image.
Thanks for your help.
`$nextimageobject = new Image($_zp_current_album, $nextimage);`
Then use `$nextimageobject->getCustomImage(....);`
or `$nextimageobject->getThumb();`
` <?php // BEGIN prefetch next image<br />
if (hasNextImage()) {
$my_image_array = $_zp_current_album->getImages(0);
$my_nextimage = $my_image_array[imageNumber()];
$my_nextimage_object = new Image($_zp_current_album, $my_nextimage);
$my_nextimage_url = $my_nextimage_object->getSizedImage(getOption('image_size'));
echo ''."n";
echo ''."n";
} // END prefetch next image ?>`
Please let me know if there's anything wrong with it.
` $my_image_array = $_zp_current_album->getImages(0);
$n = imageNumber();
if ($n < count($my_image_array) {
$my_nextimage = $my_image_array[$n];
$my_nextimage_object = new Image($_zp_current_album, $my_nextimage);
$my_nextimage_url = $my_nextimage_object->getSizedImage(getOption('image_size'));
echo ''."n";
echo ''."n";
}`
Not sure why you have the two echo statements. Isn't the second enough?
"And do you know if mozilla-based browsers load this last?"
Yep. Mozilla-based browsers should only start prefetching links when the browser becomes idle, meaning every element on the current page and even on other open tabs are finished loading. See "How is browser idle time determined?" for technical details.
sbillard: Ah, so `if ($n < count($my_image_array))` is more efficient than `if (hasNextImage())`? Thanks for the tip.
If you mean why I have 2 prefetch hints, one for `getNextImageURL()` and one for `$my_nextimage_url`, it's because the first is the URL to the next page, while the second is the URL to the next image itself. I suppose I should choose less confusing variable names.
If you mean why I don't combine everything into 1 echo statement, no reason. Just clearer to write.
zenphoto devs rock.
P.S. Hmm bbpress forums are stripping the slash in \n.
http://www.tummblr.com/my-code/zenphoto-plugin-link-prefetching-hints/