I have done tests with two codes that do the same, load a defined selection with the options of a request that is made bd. php code:
<div id="Contenedor" style="position:absolute; height: 0px; width: 0px; opacity: 0;">
<select class="ui-keyboard-input ui-widget-content ui-corner-all ui-keyboard-input-current" size='9'; style="text-align: left; width: 250px; height: 180px" id="Select" disabled="disabled" aria-haspopup="true" role="textbox" type="text">
<?php
$query= "SELECT 'id','name' FROM 'lista'";
$data=SQL($query);
while ($fila = mysql_fetch_assoc($data)) {
$code= $fila['id'];
$name= $fila['name'];
$conc= $id.": ".$name;
?>
<option value="<?php echo $code;?>"><?php echo $conc;?></option>
<?php
}
?>
</select>
</div>
Javascript code for the same select:
$.get('/pedirLista.php',{
funcion:'listar'
}).done(function(data){
var sele=(JSON.parse(data));
for(x=0; x<sele.length;x++){
$("#Select").append(new Option(x+': '+sele[x],x));
}
});
I put the complete code but what it consumes time in each one of the routines is the filling loop of the options, the While in case of php and the for in case of javascript. Performing different tests it turns out that the javascript code takes a minute to load 4000 records while php takes about 800 milliseconds, how is such a difference possible? Is there anything that can be improved in javascript? My question is justified by topic that doing it through javascript, the select is loaded and I do not have to reload every time I enter the section, while by php, every time the section is loaded I'm making a call to bd.