I'm new in the field of JSON and I've done a lot of research the past week on the topic in regards to only showing a certain quantity and using a button click to show X count after I initially load 12. I have learned how to call an API with PHP, extract data from the JSON, use a foreach statement with PHP to output the JSON contents but I'm not finding much luck in a definitive answer or explanation if performance is effected when I use a button to show the next quantity.
The JSON I am calling has well over 100 objects with each object having up to 20 values (my terminology understanding after reading here) and it's updated every hour with PHP. I thought it would be good performance to render the first 12 with PHP after reading how to limit the statement:
$showList = 12;
$countRecords = 0;
foreach($products as $product) {
if ($countRecords < $showList) {
// more code
}
++$countRecords;
}
and reading a few questions that suggest doing this on the server side.
After referencing several questions on how to create a button click to load the next 12 count I'm worried that using .slice()
would hinder performance because it looks like it goes through the entire file each time then slices the content:
I did see another approach where a hidden class was added and the button removes the class but wouldn't that defeat performance:
another approach with AJAX:
I did think about modifying the counter:
What is the appropriate execution to load more objects with an Ajax button click that wouldn't delay the return or hinder on performance if I do have a large JSON file or is there no effect with .slice()
?