Speeding up Pixelpost blog browsing


Pixelpost is a very popular framework for photoblogs due to its simplicity and ease of tweaking. A while back I posted an article on how to enable keyboard navigation on a pixelpost photoblog. It works very well considering it allows mouse free browsing. But the browsing experience can be improved even more.

Lets consider how a photoblog is browsed most of the time. A visitor typically lands on a home page showing the latest image and goes through the previous images sequentially, spending a few seconds on each image. Leveraging this fact, if the “previous” image is downloaded in the background using javascript right after the current image, it will be almost if not completely ready for viewing when the visitor is on the “previous” image page. The same can be done for the “next” image, but in most of the cases that image will already be in the browser cache.

This is a very simple change for a tangible usability benefit. Below are my tweaks:

index.php:

// expose the previous image name through tags, so previous images can be
// pre-downloaded in the background for faster browsing experience
$tpl = ereg_replace("<IMAGE_PREVIOUS_NAME>",$image_previous_name,$tpl);

templates/theworldin35mm/image_template.html:

window.onload = function() {
  ...
  var prevImg = new Image(); // for downloading prev image in background

  img.onload = function(evt) {
    ...
    // after current image load, load previous image in the background
    if('<IMAGE_PREVIOUS_NAME>' != '') {
      prevImg.src = '<SITE_URL>images/<IMAGE_PREVIOUS_NAME>';
    }
  }
  ...
};

To verify that this extra javascript is actually doing its job, look at the Net section in Firebug (in Firefox browser, ofcourse). Clear the cache first. On first page load it will show several items getting downloaded. On left arrow, the previous image page will load, and then you can see that an extra image got downloaded at the bottom. Compare with and without my code. Here is a screenshot:

Testing pre-download of previous image

,

  1. #1 by Francesco Gallarotti on March 6, 2010 - 9:22 pm

    Talk about being in complete sync you and I… Without having read your post I have changed this weekend the homepage of my website to be a slideshow with a simple jQuery script that loads three slides at a time, two slides are used for the transition and the third to pre-load the next image in the slideshow…

  2. #2 by therider on March 6, 2010 - 9:31 pm

    Your homepage looks very cool. But, did you have to make another set of images for the slideshow ? You can show your current images cropped by css in square format on the home page.

  3. #3 by Francesco Gallarotti on March 6, 2010 - 9:53 pm

    I could, but I would have no control over the cropping which is something I cannot accept. Didn’t take too long to prepare the slides. Once in a while i will update, not too often.
    It was just a little too static as a homepage.

  4. #4 by Francesco Gallarotti on March 6, 2010 - 9:56 pm

    RE your pixelpost hack, an obvious improvement would be to do the same also for the NEXT image, of course, for those users that land at a page different than the last one or that browse in the archives to a specific image

  5. #5 by Francesco Gallarotti on March 6, 2010 - 10:01 pm

    I inserted your code in my pixelpost… I guess the question is… how do i know it’s working?

  6. #6 by Francesco Gallarotti on March 6, 2010 - 10:03 pm

    Debugged the javascript and it’s not working. It’s trying to load ‘http://www.gallarotti.net/photoblog/images/‘ (no replacement of the tag occurs)

  7. #7 by therider on March 6, 2010 - 10:06 pm

    First, see if you even have $image_previous_name variable available in your index.php. IF you don’t, then I have to send you relevant code from my file.

    To see if it is working, just watch the Net section of firebug. Without my code, you will not see any other image getting downloaded, but with the code, you will.

  8. #8 by Francesco Gallarotti on March 6, 2010 - 10:07 pm

    Ok I found the right place to put that line of code in the index.php and now it works. It needs to be placed after the following lines:

    $image_previous_name = $previous_row['image'];
    $image_previous_id = $previous_row['id'];

  9. #9 by Zhiwan on March 23, 2010 - 12:07 pm

    Hey,

    I love all the info you are giving. I tried to use your code, but when I check firebug, I don’t see an additional image downloaded like when I check yours. Does the code work with a template other than “the world in 35mm”? My template uses jQuery and not mootools. Thanks!

  10. #10 by therider on March 23, 2010 - 12:25 pm

    Hi Zhiwan,

    I have not had a chance to try this for other templates. But the basic logic can be implemented with minor tweaks for any template. I will take a look at your photoblog and see if there are obvious problems to use my code as is.

    -Joy

  11. #11 by yudi ristu prihawan on April 21, 2010 - 10:38 pm

    hi, my name yudi. i’m from Indonesia.

    Nice post, and thanx for your tutorial’s. Don’t forget to visit my blog at: semuabilang.blogspot.com

    thanx

(will not be published)