tags:

views:

63

answers:

2

So I have my own webpage here, which is a sortable thumbnails page. The load() event activates each thumbnail when the first related image is loaded. Since I'm grabbing <img> tags and text content from a hidden div on the page, the thumb activation prevents the user from clicking through to a yet-unloaded image and then waiting while the preload takes place in the background.

The call is pretty simple:

$('#content img:first-child').load(activateThumb).each(function(){
    if(this.complete || this.complete === undefined)this.load();});

the .each() catches any cached images and manually triggers the load() event. Worked great and was a fast and lean website. Now, as the site continues to grow, there are over 100 <img> tags in the single HTML file and I'm wondering if there's a conventional limit that I'm approaching. Should I split the page onto 35 different html files? Should I lose the tags and the slick preloading effect in favor of a server-side request for the images on demand?

What's your instinct, as a good programmer?

A: 

You can do it like many Web 2.0 sites do it:

  1. In the beginning, load the images displayed on currently visible part of the page.
  2. Then load other images when user scrolls the page down.
shamittomar
Did you look at the page I was describing? It requires no scrolling and none of the preloaded images are displayed at the beginning.
Isaac Lubow
I click your link and am taken to a page with a scrollbar, I'm also taken to a page with images on it immediately. I'm not sure why you downvoted him.
Robert
@Robert, that's what I'm thinking :)
shamittomar
@Isaac - it may not require scrolling on your monitor, but for us normal folk (1200px vertical) it definitely does.
Ian Henry
@Ian, mine is 768px vertical :(
shamittomar
@shamittomar, only thumbnails are visible at the outset. If you meant only load the images *pointed to* by the thumbnails presently displayed, it still doesn't address my question. If I follow your advice, once the user scrolls down, all images load and I'd have the same page structure and the same question.I hope I've been clear: the page runs great now, but I am asking whether the large number of `img` tags would mess anyone up.
Isaac Lubow
@Isaac: If your website users are in developed countries than you do not need to worry because the Internet bandwidth is very very good there.
shamittomar
Fair enough. Thanks!
Isaac Lubow
A: 

Well there is no clear limit. You can continue doing the way you have done on your site for as many images as possible.

But it's just that the user might get frustrated while waiting for all the images to get 'activated'.

So in turn what you could do is to have pagination & display say 20 images per page. This way you make the image loading relatively faster.

Also after you load page1, if the user is still in page1 you could start pre-fetching page2. So as the user clicks page2 he sees a very responsive site :)

There is no one rule here. In fact if you see Google Images now a days they do something like what you have done.

MovieYoda
Well my reasoning is this: The user doesn't _have_ to wait for each and every image to be activated. The active ones let them know which can be viewed right away. And while they are looking at those, the image loading proceeds... It's a great technique but I was simply worried about what would happen if the page became too massive.
Isaac Lubow
nothing would happen. It's great the way it is now. Go ahead. If it becomes too much of a bottleneck later on. Then think of pagination. But for now your approach is prefect.
MovieYoda