Delay in loading PHP page with image

2

I have a PHP page that loads the 570 records in 2 seconds.

The problem is that when I insert images, even if small (3 KB) the loading time goes to 10 seconds.

Do you have any way to load these images?

    <?php 
    while($consulta1 = mysql_fetch_array($result1)){;  
    ?>

    <div class="relacao">
      <div class="nome-album-artista"><?php echo $consulta1["nm_album"].'<br><i>'.$consulta1["nm_cantor"].'</i>'; ?></div>
    </div>

    <div id="botoes">
      <div class="btn_alterar"><a href="album_alterar.php?album=<?php echo $consulta1["id_album"]?>" title="Alterar"><img src="images/valid-icon.png"></a></div>
    </div>

    <?php
    }
    mysql_free_result($result1); 
    mysql_close($conn)
    ?>
    
asked by anonymous 16.01.2015 / 18:46

3 answers

2

One more possibility for you is to upload images only when they really are needed. A project called Lazy Load (jQuery) does just that. It will cause the images to load only when they are in the user's viewport.

Project website:

link

    
16.01.2015 / 21:54
3

Maybe you can not find the solution to your problem here as it is a very different case that covers many theories about networks, memory, etc. .. So it excludes all possibility the problem is in your code.

However, I want to introduce you to YSlow as ANSWER of your question. It offers suggestions for improving page performance and summarizes the components of your page.

YSlow looks at web pages and why they are slow. Made for high-performance websites.

Download: link

Source: link

    
16.01.2015 / 20:29
1

Before trying to optimize, you need to know what happens.

In the case of PHP and MySQL (the other BDD), we have 4 points:

  • BDD side treatment time
  • PHP side treatment time
  • data transmission time between server and browser
  • browser page build time
  • For point 1 you can check using this:

     $start_time = microtime(true);   // Antes
     $result = @mysqli_query($handle,$query);
     $end_time = microtime(true);   // Depois
     $ecart = $end_time - $start_time;  // Diferença
    

    For point 2, you can do the same thing: put a microtime (true) at the top of the PHP page, one on the last line, calculate the difference and echo the result.

    After that, you will be able to see if the exposure time is the same as the calculation: if the "PHP" time is 0.03 seconds, the Mysql time of 0.01 which takes 3 seconds to see the page, this means that the problem does not happen in Point 1 or Point 2 ...

    On Point 4, there is one thing to know: I do not know the structure of your page, but browsers start displaying the contents of the pages with tables, only after receiving the whole code. For example, if you have 500 results (after the query) and you put the results in a table only (then you have the TABLE tag at the top of the page, then 500 TD and TR tags for the 500 results and at the bottom of the page tag of the TABLE), the browser will expect to receive the 500 data BEFORE starting the show anything. To avoid this, you need to open and close the table, for example every 30 results. So the user will quickly see the top 30 when the other results will continue to arrive. This will not change the "real" time but it will change the perception of time a lot!

    Last chance: Your internet connection is weak.

    PS: a detail. The "mysql" module is considered obsolete. Need to use mysqli.

        
    17.01.2015 / 20:46