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?