using prefetching to speed slideshow/browsing dramatically

dmd
dmd's picture

Joined: 2003-06-28
Posts: 50
Posted: Sun, 2005-04-03 03:55

It seems to me that use of Mozilla/Firefox's prefetching capability (http://www.mozilla.org/projects/netlib/Link_Prefetching_FAQ.html) would make slideshows dramatically better looking, and make paging through albums much, much faster as well.

Has anyone looked into implementing this? I'd be happy to (it seems easy enough), but if others have thought about it deeply and rejected it already, I'd like to hear about it first. (It seems so obvious and trivial and dramatically a good thing, it puzzles me why it hasn't already been done.)

 
dmd
dmd's picture

Joined: 2003-06-28
Posts: 50
Posted: Sun, 2005-04-03 05:21

Ok, I feel dumb now - gallery already does this!

But... why isn't Firefox paying any attention to it? I'm watching in Ethereal, and it's quite clearly not doing it.

 
dmd
dmd's picture

Joined: 2003-06-28
Posts: 50
Posted: Sun, 2005-04-03 05:28

Ok, I see why now - it's prefetching the HTML, but not the image.

It would be nice if it would prefetch the image, too. Gallery code is scaring me - I can't seem to figure out how to do this. Could someone who's familar with it tell me how to add a prefetch line that'll load the next and previous page's photos?

Basically - in the context of view_photo.php, how can I determine the full and thumb versions of the next and previous images?

I see that makeAlbumUrl($gallery->session->albumName, $navigator['allIds'][$navpage-1]) and makeAlbumUrl($gallery->session->albumName, $navigator['allIds'][$navpage+1]) will give me the previous and next pages, but I want the previous and next photos.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Tue, 2005-04-05 16:55

So you are saying the in for example my test view_photo.php page has this as the source

<link rel="first" href="http://langleycom.com/g1/album13/andrew_sleep_chair" >
   <link rel="prev" href="http://langleycom.com/g1/album13/andrew_sleep_chair" >
  <link rel="next" href="http://langleycom.com/g1/album13/brian_dave_wendy_cath_c" >
   <link rel="last" href="http://langleycom.com/g1/album13/pats_kids" >

and it only prefetches the HTML? There was a post about this code incrementing the image count. You are saying it does not get the image as well?

So you are saying that it should prefetch the image as well like <link rel="next" href="http://langleycom.com/g1/albums/album13/DCP_1826.sized.jpg" > in addition to the prefetching the HTML?
Dave

 
dmd
dmd's picture

Joined: 2003-06-28
Posts: 50
Posted: Wed, 2005-04-06 00:37

Correct. Can't hurt, and if the user indeed goes to the next/prev page as expected, it would make gallery amazingly responsive.

 
dmd
dmd's picture

Joined: 2003-06-28
Posts: 50
Posted: Fri, 2005-04-08 19:47

So, is this a lot harder than I thought?

 
dmd
dmd's picture

Joined: 2003-06-28
Posts: 50
Posted: Fri, 2005-04-08 20:45
 diff view_photo.php.orig  view_photo.php

(see unified diff below)

I'm sure I'm forgetting a thousand special cases, but this seems to work pretty well for me!

 
fryfrog

Joined: 2002-10-30
Posts: 3236
Posted: Fri, 2005-04-08 22:01

I don't spose there is a chance you could run that as a "diff -u" instead? I just find it easier to read :)

 
dmd
dmd's picture

Joined: 2003-06-28
Posts: 50
Posted: Sat, 2005-04-09 01:22
--- view_photo.php.orig 2005-04-18 20:49:04.000000000 -0700
+++ view_photo.php      2005-04-18 20:54:26.000000000 -0700
@@ -226,12 +226,41 @@
                if ($navigator['allIds'][0] != 'unknown') { ?>
    <link rel="first" href="<?php echo makeAlbumUrl($gallery->session->albumName, $navigator['allIds'][0]) ?>" >
 <?php          }
-               if ($navigator['allIds'][$navpage-1] != 'unknown') { ?>
+               if ($navigator['allIds'][$navpage-1] != 'unknown') {
+                   $prevphotoindex = $gallery->album->getPhotoIndex($navigator['allIds'][$navpage-1]);
+                   $prevphoto = $gallery->album->getPhoto($prevphotoindex);
+                   if (! $prevphoto->isMovie()) {
+                       if ($prevphoto->image->resizedName) {
+                           $prevphotoURL = $gallery->album->getAlbumDirURL("full") . "/" . $prevphoto->image->name . ".sized." . $prevphoto->image->type;
+                       } else {
+                           $prevphotoURL = $gallery->album->getAlbumDirURL("full") . "/" . $prevphoto->image->name . "." . $prevphoto->image->type;
+                       }
+                       print "<link rel=\"prefetch\" href=\"$prevphotoURL\">\n";
+                   }
+
+
+
+
+
+
+                   ?>
    <link rel="prev" href="<?php echo makeAlbumUrl($gallery->session->albumName, $navigator['allIds'][$navpage-1]) ?>" >
 <?php          }
        }
        if ($navigator['allIds'][$navcount - 1] != $id) {
-               if ($navigator['allIds'][$navpage+1] != 'unknown') { ?>
+               if ($navigator['allIds'][$navpage+1] != 'unknown') {
+                   //dmd
+                   $nextphotoindex = $gallery->album->getPhotoIndex($navigator['allIds'][$navpage+1]);
+                   $nextphoto = $gallery->album->getPhoto($nextphotoindex);
+                   if (! $nextphoto->isMovie()) {
+                       if ($nextphoto->image->resizedName) {
+                           $nextphotoURL = $gallery->album->getAlbumDirURL("full") . "/" . $nextphoto->image->name . ".sized." . $nextphoto->image->type;
+                       } else {
+                           $nextphotoURL = $gallery->album->getAlbumDirURL("full") . "/" . $nextphoto->image->name . "." . $nextphoto->image->type;
+                       }
+                       print "<link rel=\"prefetch\" href=\"$nextphotoURL\">\n";
+                   }
+                   ?>
   <link rel="next" href="<?php echo makeAlbumUrl($gallery->session->albumName, $navigator['allIds'][$navpage+1]) ?>" >
  <?php                 }
                if ($navigator['allIds'][$navcount-1] != 'unknown') { ?>
 
dmd
dmd's picture

Joined: 2003-06-28
Posts: 50
Posted: Fri, 2005-09-23 20:44

Any chance this could get incorporated into G1? It makes my site ( http://wurble.net/gallery/ ) appear way faster than any other I've ever seen, and that's only a good thing for people's perception of Gallery...

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Sat, 2005-09-24 03:43

dmd... the best way for things to get into the next version is to post your diff in http://sourceforge.net/tracker/?group_id=7130&atid=307130 and make your case.

Then you can Vote on it as well http://gallery.menalto.com/sfvote_help

Dave

Gallery Frames / Mods || G1 Test Gallery