Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Verify images loaded?

by JimJx (Beadle)
on Jul 09, 2003 at 00:17 UTC ( #272519=perlquestion: print w/replies, xml ) Need Help??

JimJx has asked for the wisdom of the Perl Monks concerning the following question:

I have what I hope is a wuick and easy question....

I have 25 small images (~1.5k each) and I will need to have half of them at most displayed on a page at any one time. Is there any way to verify that all images have been loaded before the page is displayed? Or would I be better off just doing a preload of all of them?

Thanks in advance for any input or advice! :-)

Jim

Replies are listed 'Best First'.
Re: Verify images loaded?
by tcf22 (Priest) on Jul 09, 2003 at 01:09 UTC
    It sounds like you are working with a CGI, you could just paginate them. For example build a list, then display so many per page.
    use strict; use warnings; use CGI; use constant PICS_PER_PAGE => 20; my @pics = ('pic1.jpg', 'pic2.jpg'); my $cgi = new CGI; my $start = $cgi->param('start') || 0; foreach($start..($start + PICS_PER_PAGE - 1)){ last unless(defined $pics[$_]); print qq(<IMG src="$pics[$_]">); } my $newstart = $start + PICS_PER_PAGE; print qq(<INPUT type="hidden" name="start" value="$newstart">);
    Replace PICS_PER_PAGE with the number of pictures per page, and load @pics, with the picture names.

    You can't really check to see if the browser has already loaded the images, but you can generate JavaScript to only preload the images that are going to be displayed on this particular page. You already have the list of images that are going to be displayed on the current page.

    Update:Took care of default case, where $start was undef.
    Update2:Gave more explanation. I read the question too quick, and didn't answer all of it.
Re: Verify images loaded?
by markexpjp (Novice) on Jul 09, 2003 at 03:54 UTC
    Better off just doing a preload of all of them (pretty small anyway), you can't do anything from the server side, short of adding an Apache module or something to check that the client had requested and been sent at least half of the images. Or you might be able to do it with Perl and server logs, provided you have permission to change the format of your server logs and that Perl has permission to read them... but this is very silly. I think you're better off just preloading all and not worrying about it. And now for something completely different.

    ___________________________
    10 poke53280,a:poke53281,a
    20 ?"c64 rules ";
    30 a=a+1:ifa=16thena=0:goto 10
      check that the client had requested and been sent at least half of the images.

      Except that that's impossible. The HTML page must be sent first so that the client will know which images to request. If the server doesn't send the HTML, it will never receive requests for the images in the first place, and if it sends the HTML, the client will display it.

Re: Verify images loaded?
by Mirage (Sexton) on Jul 09, 2003 at 13:07 UTC
    You can't verify it with perl, but i think there are possibilities with client-side methods such as javascript, java or flash, but who wants that... :)

    I don't know if it gives the results you want, but you may want to look at those.

      I think JavaScript would be your best bet.

      But what is your reason for not displaying the page until they get loaded? It won't make the page load any faster. People are already used to seeing images load after the page is displayed.

      Agreed. I'll add this: The behavior I witness in my browser is that the browser will load the page, parse it, and then make requests for the images. But even with javascript, I'm not sure that you can prevent the display of the page until all the images are loaded.
Re: Verify images loaded?
by JimJx (Beadle) on Aug 03, 2003 at 23:09 UTC
    Sorry about the delay inresponding but new job, etc. I had to be away for a while. Thanks for all of the replies!

    The problem I was experiencing was one that I had a page that would load about half of the images, never all of them. I did get a chance to get with a couple other people here locally and decided to go with the preload even though Javascript and I don't get along very well. Read that as I am notas good at it as I am perl, and I rate myself as an extreme novice at Perl but hopefully learning more everyday..... :-)

    Thanks again for all of the replies!
    Jim

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://272519]
Approved by tcf22
Front-paged by tcf22
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (1)
As of 2022-10-02 23:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (13 votes). Check out past polls.

    Notices?