What is the best way to load a website? [closed]

2

I am developing a website similar to Mercado Libre, what I want is for it to load in a fast way. I have seen that YouTube does not render all the content when starting, but after loading the page inserts the content and data of the video, then loads the related videos. I would like to upload my website in this way. The question would be Is this advisable? How is this process performed?

An example of how I would load my website normally:

 <html> 
        <head> ESTILOS</head>
        <body>
          <?php
           aquí se hace la consulta y se imprimen los productos
          ?>
          AQUÍ LOS SCRIPTS
        </body>
   </html>

They recommended that I use AJAX to load the content, according to that recommendation, the code introducir el código aquí would change to the following:

 <html> 
        <head> ESTILOS</head>
        <body>
          <plantilla html como se mostrarían los productos>
          AQUÍ LOS SCRIPTS
          AL TERMINAR DE CARGAR LA PAGINA SE HACE LA CONSULTA CON AJAX Y 
          SE IMPRIMEN LOS PRODUCTOS CON JS.
        </body>
   </html>

Another option would be to do it as YouTube, if you look at the source code of any YouTube video and how it loads, you will realize that there is a script that contains all the information to show on the page in the first instance. I imagine that the process that YouTube performs would be similar to the following:

<html> 
        <head> ESTILOS</head>
        <body>
          <plantilla html como se mostrarían los productos>
          <?php
           aquí se hace la consulta PERO NO se imprimen los productos
           Los datos de la consulta se pasan a JSON
          ?>

          AQUÍ LOS SCRIPTS
          AL TERMINAR DE CARGAR LA PAGINA SE IMPRIMEN LOS PRODUCTOS CON JS 
          CON LOS DATOS DEL JSON.
        </body>
   </html>

Which of these methods would be better? Is there an alternative?

    
asked by Raymond Medina 19.05.2018 в 16:00
source

1 answer

0

My answer may be a little vague, but that has to do with adding the content loading scripts to the end of the code, and instead of showing a loading bar, a content-appearing "template" is displayed that has not received the content load. All this would be best done with Ajax ... Facebook also began to implement that dynamic loading technology to streamline the views ... I would recommend looking for a tutorial on how to use ajax to dynamically load content and combine it with what you say.

    
answered by 19.05.2018 в 20:07